data-structures - 日志搜索服务的数据结构?
问题描述
几个月前,我被要求设计一个服务,它需要一个开始和结束时间间隔,并列出按异常类型/代码分组的异常/错误数量。基本上,目的是创建或使用现有数据结构进行有效搜索。这是我编码的。
public class ErrorDetail{
private int code;
private String message;
}
public class ExceptionSearchService
{
private Map<Long, ErrorDetail> s = new TreeMap<Long, ErrorDetail>();
public ArrayList<ErrorDetail> getErrors(long start, long end){
ErrorDetail e1 = find(start, s);
ErrorDetail e2 = find(end, s);
//do an in order traversal between e1 and e2 and add it to an array list and return
}
public void addError(long time, ErrorDetail e){
s.put(time,e);
}
}
我意识到我不应该提到 TreeMap,而是应该有我自己的类,比如 TreeNode,但我的想法是有一个树结构和一个分布式的,因为我们正在谈论成千上万的服务每分钟服务数百万个请求并产生错误.
在这种情况下我可以使用更好的数据结构吗?
解决方案
推荐阅读
- python - 如何在使用 np.random.normal() 时生成相同的随机数组
- javascript - 数组串联差异
- r - add_pval: textsize 不会改变
- powershell - 审核登录远程桌面的用户,过滤掉本地 IP 地址
- python - 在 Python Selenium 中使用 if else 或 try except 查找元素
- ios - XCFramework, dyld 缓存加载错误:共享缓存文件 open() 失败
- python - 导入内部函数
- flutter - 在 null 上调用了方法“timeZone”。(扑)
- flutter - flutter 将文件保存在用户选择的目录中
- powershell - local-exec 中的 Powershell(Azure DevOps Pipelines)