将时间序列数据的滑动窗口存储在磁盘上

huangapple go评论79阅读模式
英文:

Storing sliding window of time-series data on disk

问题

我写了一个服务器,它消费一个按时间顺序排列的事件(时间序列)的实时流,并维护一个滑动窗口(24小时)的数据。它只支持一种类型的查询:

获取从时间戳T开始的N秒事件

我目前正在使用leveldb,其中unix时间戳作为键。这个方法还可以,但是由于leveldb是一个LSM数据库,删除操作(墓碑)比较耗时。

有人能为这种情况提供一个更好的解决方案/数据存储吗?

  • 数据太大无法存储在内存中
  • 服务器是用Go语言编写的
英文:

I've written a server which consumes a live stream of chronologically ordered events (time-series) and maintains a sliding window (24h) of the data. It only supports one type of query:

get N seconds of events starting at timestamp T

I'm currently using leveldb with unix timestamps as the keys. This works alright but, since leveldb is a LSM, the deletes are expensive (tombstones).

Can anyone suggest a better solution/datasore for this use case?

  • The data is too big to store in memory
  • The server is written in Go

答案1

得分: 2

最简单的解决方案就是始终使用两个LevelDB数据库——一个用于当前日期,另一个用于前一天。只向当前日期的数据库写入数据。

每天执行以下操作:

删除前一天的数据库(previous)
将当前日期的数据库(current)赋值给前一天的数据库(previous)
创建一个新的当前日期的数据库(current)

这样可以保存近两天的数据,而不仅仅是一天,而且轮换非常简单。

英文:

The simplest solution is just always have 2 leveldb's - for the current day and the previous one. And you write to the current only.

And once a day you just

delete(previous)
previous := current
current := new()

You may then save almost 2 days instead of one, but rotation is really easy.

huangapple
  • 本文由 发表于 2015年7月16日 00:12:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/31435702.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定