tigercat.us
剖析 carbon 核心代码
http://www.tigercat.us/dissecting-carbon.html
一个网络服务,接收时间序列数据包,使用时间序列数据库 通常为 whisper 进行持久化。 Carbon 代码组织复杂,为了扩展和性能的需要,有 relay/hashing/amqp/aggregate/pickle 之类的优化点. Carbon 早期使用 socket and select 完成网络 IO,代码还算清晰,现在引入了 twisted,几乎算是一门 Python 方言了. Aggregator 暂时不用了解,之后可以了解外置 aggregator 来减少 IO,如 statsd。 Carbon 使用 twisted,不显示调用 socket,相关逻辑还不太好找. Carbon 对网络包的处理,这里仅看 TCP line 格式,其他还有 UDP、pickle 协议等. Invalid line received from client. S, ignoring [. Filter out NaN values. Use current time if none given: https:/ github.com/graphite-project/carbon/issues/54. 这行代码完...
tigercat.us
剖析 whisper
http://www.tigercat.us/dissecting-whisper.html
一种时间序列 (key, value, timestamp) 数据库,只是库,而非网络服务. 接口简单 create/update/fetch 数据,whisper 创建的 .wsp 文件路径的一部分相当于 key,(value, timestamp) 存放在 .wsp 文件里. File = Header,Data. Header = Metadata,ArchiveInfo. Metadata = aggregationType,maxRetention,xFilesFactor,archiveCount. ArchiveInfo = Offset,SecondsPerPoint,Points. Point = timestamp,. 由于预先定义了数据的 retension 策略,whisper 文件使用的磁盘空间大小在创建时就固定了. 基于 cassandra,缓解 IO 、 gorilla. Carbon 根据时间序列数据中的 key 及其对应的 retension 策略,调用 whisper 创建 wsp 文件,比如 home.aqi.pm25 的 key 创建成. 对于单条 (key, v...