go-carbon

go-carbon

Golang实现的高性能Graphite服务器

go-carbon项目采用Golang重新实现了Graphite服务器,保留了Agent、Cache、Persister的经典架构。该项目支持通过TCP、UDP、HTTP和Kafka等多种协议接收指标数据,并提供存储模式配置、数据聚合、缓存管理和多核心持久化等核心功能。测试表明,go-carbon在处理性能上全面超越了默认的carbon实现,能够有效应对大规模指标数据的处理需求。其优化的设计使其能够高效处理每分钟数十万计的指标数据。

go-carbonGraphite指标处理性能优化配置管理Github开源项目

deb rpm

Table of Contents

go-carbon Build Status

Golang implementation of Graphite/Carbon server with classic architecture: Agent -> Cache -> Persister

Architecture

Features

  • Receive metrics from TCP and UDP (plaintext protocol)
  • Receive metrics with Pickle protocol (TCP only)
  • Receive metrics from HTTP
  • Receive metrics from Apache Kafka
  • storage-schemas.conf
  • storage-aggregation.conf
  • Carbonlink (requests to cache from graphite-web)
  • Carbonlink-like GRPC api
  • Logging with rotation support (reopen log if it moves)
  • Many persister workers (using many cpu cores)
  • Run as daemon
  • Optional dump/restore restart on USR2 signal (config dump section): stop persister, start write new data to file, dump cache to file, stop all (and restore from files after next start)
  • Reload some config options without restart (HUP signal):
    • whisper section of main config, storage-schemas.conf and storage-aggregation.conf
    • graph-prefix, metric-interval, metric-endpoint, max-cpu from common section
    • dump section

Performance

Faster than default carbon. In all conditions :) How much faster depends on server hardware, storage-schemas, etc.

The result of replacing "carbon" to "go-carbon" on a server with a load up to 900 thousand metric per minute:

Success story

There were some efforts to find out maximum possible performance of go-carbon on a hardware (2xE5-2620v3, 128GB RAM, local SSDs).

The result of that effort (in points per second):

Performance

Stable performance was around 950k points per second with short-term peak performance of 1.2M points/sec.

Efficient metric namespace patterns for trie index

Putting the most common namespaces at the beginning of the metric name could be beneficial for scaling. This doesn't affect the performance of trigram index. But when you decide to switch to trie index for serving higher number metrics in a single go-carbon instance, your query would be more efficient. At the same time, this naming pattern could lead to better metric namespace hierarchy.

For example: querying sys.cpu.loadavg.app.host-0001 would be faster than querying sys.app.host-0001.cpu.loadavg using trie index. Especially when you have tens of thousands hosts (host-0001, ..., host-9999), they all share the same prefix of sys.cpu.loadavg.app.host- in trie index, and they are compared only once during query. So this patterns leads to better memory usage and query performance when using trie+nfa/dfa index.

More details could be found in this blog: To glob 10M metrics: Trie * DFA = Tree² for Go-Carbon.

Installation

Use binary packages from releases page or build manually (requires golang 1.8+):

# build binary
git clone https://github.com/go-graphite/go-carbon.git
cd go-carbon
make

We are using <a href="https://packagecloud.io/"><img alt="Private Maven, RPM, DEB, PyPi and RubyGem Repository | packagecloud" height="46" src="https://packagecloud.io/images/packagecloud-badge.png" width="158" /></a> to host our packages!

At this moment we are building deb and rpm packages for i386, amd64 and arm64 architectures. Installation guides are available on packagecloud (see the links below).

Stable versions: Stable repo

Autobuilds (master, might be unstable): Autobuild repo

We're uploading Docker images to ghcr.io

Also, you can download test packages from build artifacts: Go to list of test runs, click on PR name, and click on "packages-^1" under "Artifact" section.

Configuration

$ go-carbon --help
Usage of go-carbon:
  -check-config=false: Check config and exit
  -config="": Filename of config
  -config-print-default=false: Print default config
  -daemon=false: Run in background
  -pidfile="": Pidfile path (only for daemon)
  -version=false: Print version
[common] # Run as user. Works only in daemon mode user = "carbon" # Prefix for store all internal go-carbon graphs. Supported macroses: {host} graph-prefix = "carbon.agents.{host}" # Endpoint to store internal carbon metrics. Valid values: "" or "local", "tcp://host:port", "udp://host:port" metric-endpoint = "local" # Interval of storing internal metrics. Like CARBON_METRIC_INTERVAL metric-interval = "1m0s" # Increase for configuration with multi persister workers max-cpu = 4 [whisper] data-dir = "/var/lib/graphite/whisper" # http://graphite.readthedocs.org/en/latest/config-carbon.html#storage-schemas-conf. Required schemas-file = "/etc/go-carbon/storage-schemas.conf" # http://graphite.readthedocs.org/en/latest/config-carbon.html#storage-aggregation-conf. Optional aggregation-file = "/etc/go-carbon/storage-aggregation.conf" # It's currently go-carbon only feature, not a standard graphite feature. Optional # More details in doc/quotas.md # quotas-file = "/etc/go-carbon/storage-quotas.conf" # Worker threads count. Metrics sharded by "crc32(metricName) % workers" workers = 8 # Limits the number of whisper update_many() calls per second. 0 - no limit max-updates-per-second = 0 # Sparse file creation sparse-create = false # use flock on every file call (ensures consistency if there are concurrent read/writes to the same file) flock = true enabled = true # Use hashed filenames for tagged metrics instead of human readable # https://github.com/go-graphite/go-carbon/pull/225 hash-filenames = true # specify to enable/disable compressed format (EXPERIMENTAL) # See details and limitations in https://github.com/go-graphite/go-whisper#compressed-format # IMPORTANT: Only one process/thread could write to compressed whisper files at a time, especially when you are # rebalancing graphite clusters (with buckytools, for example), flock needs to be enabled both in go-carbon and your tooling. compressed = false # automatically delete empty whisper file caused by edge cases like server reboot remove-empty-file = false # Enable online whisper file config migration. # # online-migration-rate means metrics per second to migrate. # # To partially enable default migration for only some matched rules in # storage-schemas.conf or storage-aggregation.conf, we can set # online-migration-global-scope = "-" and enable the migration in the config # files (more examples in deploy/storage-aggregation.conf and deploy/storage-schemas.conf). # # online-migration-global-scope can also be set any combination of the 3 rules # (xff,aggregationMethod,schema) as a csv string # like: "xff", "xff,aggregationMethod", "xff,schema", # or "xff,aggregationMethod,schema". # # online-migration = false # online-migration-rate = 5 # online-migration-global-scope = "-" [cache] # Limit of in-memory stored points (not metrics) max-size = 1000000 # Capacity of queue between receivers and cache # Strategy to persist metrics. Values: "max","sorted","noop" # "max" - write metrics with most unwritten datapoints first # "sorted" - sort by timestamp of first unwritten datapoint. # "noop" - pick metrics to write in unspecified order, # requires least CPU and improves cache responsiveness write-strategy = "max" # If > 0 use bloom filter to detect new metrics instead of cache bloom-size = 0 [udp] listen = ":2003" enabled = true # Optional internal queue between receiver and cache buffer-size = 0 [tcp] listen = ":2003" enabled = true # Optional internal queue between receiver and cache buffer-size = 0 [pickle] listen = ":2004" # Limit message size for prevent memory overflow max-message-size = 67108864 enabled = true # Optional internal queue between receiver and cache buffer-size = 0 # You can define unlimited count of additional receivers # Common definition scheme: # [receiver.<any receiver name>] # protocol = "<any supported protocol>" # <protocol specific options> # # All available protocols: # # [receiver.udp2] # protocol = "udp" # listen = ":2003" # # Enable optional logging of incomplete messages (chunked by max UDP packet size) # log-incomplete = false # # [receiver.tcp2] # protocol = "tcp" # listen = ":2003" # # [receiver.pickle2] # protocol = "pickle" # listen = ":2004" # # Limit message size for prevent memory overflow # max-message-size = 67108864 # # [receiver.protobuf] # protocol = "protobuf" # # Same framing protocol as pickle, but message encoded in protobuf format # # See https://github.com/go-graphite/go-carbon/blob/master/helper/carbonpb/carbon.proto # listen = ":2005" # # Limit message size for prevent memory overflow # max-message-size = 67108864 # # [receiver.http] # protocol = "http" # # This receiver receives data from POST requests body. # # Data can be encoded in plain text format (default), # # protobuf (with Content-Type: application/protobuf header) or # # pickle (with Content-Type: application/python-pickle header). # listen = ":2007" # max-message-size = 67108864 # # [receiver.kafka] # protocol = "kafka # # This receiver receives data from kafka # # You can use Partitions and Topics to do sharding # # State is saved in local file to avoid problems with multiple consumers # # # Encoding of messages # # Available options: "plain" (default), "protobuf", "pickle" # # Please note that for "plain" you must pass metrics with leading "\n". # # e.x. # # echo "test.metric $(date +%s) $(date +%s)" | kafkacat -D $'\0' -z snappy -T -b localhost:9092 -t graphite # parse-protocol = "protobuf" # # Kafka connection parameters # brokers = [ "host1:9092", "host2:9092" ] # topic = "graphite" # partition = 0 # # # Specify how often receiver will try to connect to kafka in case of network problems # reconnect-interval = "5m" # # How often receiver will ask Kafka for new data (in case there was no messages available to read) # fetch-interval = "200ms" # # # Path to saved kafka state. Used for restarts # state-file = "/var/lib/graphite/kafka.state" # # Initial offset, if there is no saved state. Can be relative time or "newest" or "oldest". # # In case offset is unavailable (in future, etc) fallback is "oldest" # initial-offset = "-30m" # # # Specify kafka feature level (default: 0.11.0.0). # # Please note that some features (consuming lz4 compressed streams) requires kafka >0.11 # # You must specify version in full. E.x. '0.11.0.0' - ok, but '0.11' is not. # # Supported version (as of 22 Jan 2018): # # 0.8.2.0 # # 0.8.2.1 # # 0.8.2.2 # # 0.9.0.0 # # 0.9.0.1 # # 0.10.0.0 # # 0.10.0.1 # # 0.10.1.0 # # 0.10.2.0 # # 0.11.0.0 # # 1.0.0 # kafka-version = "0.11.0.0" # # [receiver.pubsub] # # This receiver receives data from Google PubSub # # - Authentication is managed through APPLICATION_DEFAULT_CREDENTIALS: # # - https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application # # - Currently the subscription must exist before running go-carbon. # # - The "receiver_*" settings are optional and directly map to the google pubsub # # libraries ReceiveSettings (https://godoc.org/cloud.google.com/go/pubsub#ReceiveSettings) # # - How to think about the "receiver_*" settings: In an attempt to maximize throughput the # # pubsub library will spawn 'receiver_go_routines' to fetch messages from the server. # # These goroutines simply buffer them into memory until 'receiver_max_messages' or 'receiver_max_bytes' # # have been read. This does not affect the actual handling of these messages which are processed by other goroutines. # protocol = "pubsub" # project = "project-name" # subscription = "subscription-name" # receiver_go_routines = 4 # receiver_max_messages = 1000 # receiver_max_bytes = 500000000 # default 500MB [carbonlink] listen = "127.0.0.1:7002" enabled = true # Close inactive connections after "read-timeout" read-timeout = "30s" # grpc api # protocol: https://github.com/go-graphite/go-carbon/blob/master/helper/carbonpb/carbon.proto # samples: https://github.com/go-graphite/go-carbon/tree/master/api/sample [grpc] listen = "127.0.0.1:7003" enabled = true # http://graphite.readthedocs.io/en/latest/tags.html [tags] enabled = false # TagDB url. It should support /tags/tagMultiSeries endpoint tagdb-url = "http://127.0.0.1:8000" tagdb-chunk-size = 32 tagdb-update-interval = 100 # Directory for send queue (based on leveldb) local-dir = "/var/lib/graphite/tagging/" # POST timeout tagdb-timeout = "1s" [carbonserver] # Please NOTE: carbonserver is not intended to fully replace graphite-web # It acts as a "REMOTE_STORAGE" for graphite-web or carbonzipper/carbonapi listen = "127.0.0.1:8080" # Carbonserver support is still experimental and may contain bugs # Or be incompatible with github.com/grobian/carbonserver enabled = false # Buckets to track response times buckets = 10 # carbonserver-specific metrics will be sent as counters # For compatibility with grobian/carbonserver metrics-as-counters = false # Read and Write timeouts for HTTP server read-timeout = "60s" write-timeout = "60s" # Request timeout for each API call request-timeout = "60s" # Enable /render cache, it will cache the result for 1 minute query-cache-enabled = true # Hard limits the number of whisper files that get created each second. 0 - no limit `max-creates-per-second` = 0 # Enable carbonV2 gRPC streaming render cache, it will cache the result for 1 minute streaming-query-cache-enabled = false # 0 for unlimited query-cache-size-mb = 0 # Enable /metrics/find cache, it will cache the result for 5 minutes find-cache-enabled = true # Control trigram index # This index is used to speed-up /find requests # However, it will lead to increased memory consumption # Estimated memory consumption is approx. 500 bytes per each metric on disk # Another drawback is that it will recreate index every scan-frequency interval # All new/deleted metrics will still be searchable until index is recreated trigram-index = true # carbonserver keeps track of all available whisper files in memory. # This determines how often it will check FS for new or deleted metrics. # If you only use the trie index, have

编辑推荐精选

扣子-AI办公

扣子-AI办公

职场AI,就用扣子

AI办公助手,复杂任务高效处理。办公效率低?扣子空间AI助手支持播客生成、PPT制作、网页开发及报告写作,覆盖科研、商业、舆情等领域的专家Agent 7x24小时响应,生活工作无缝切换,提升50%效率!

堆友

堆友

多风格AI绘画神器

堆友平台由阿里巴巴设计团队创建,作为一款AI驱动的设计工具,专为设计师提供一站式增长服务。功能覆盖海量3D素材、AI绘画、实时渲染以及专业抠图,显著提升设计品质和效率。平台不仅提供工具,还是一个促进创意交流和个人发展的空间,界面友好,适合所有级别的设计师和创意工作者。

图像生成AI工具AI反应堆AI工具箱AI绘画GOAI艺术字堆友相机AI图像热门
码上飞

码上飞

零代码AI应用开发平台

零代码AI应用开发平台,用户只需一句话简单描述需求,AI能自动生成小程序、APP或H5网页应用,无需编写代码。

Vora

Vora

免费创建高清无水印Sora视频

Vora是一个免费创建高清无水印Sora视频的AI工具

Refly.AI

Refly.AI

最适合小白的AI自动化工作流平台

无需编码,轻松生成可复用、可变现的AI自动化工作流

酷表ChatExcel

酷表ChatExcel

大模型驱动的Excel数据处理工具

基于大模型交互的表格处理系统,允许用户通过对话方式完成数据整理和可视化分析。系统采用机器学习算法解析用户指令,自动执行排序、公式计算和数据透视等操作,支持多种文件格式导入导出。数据处理响应速度保持在0.8秒以内,支持超过100万行数据的即时分析。

AI工具酷表ChatExcelAI智能客服AI营销产品使用教程
TRAE编程

TRAE编程

AI辅助编程,代码自动修复

Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。

AI工具TraeAI IDE协作生产力转型热门
AIWritePaper论文写作

AIWritePaper论文写作

AI论文写作指导平台

AIWritePaper论文写作是一站式AI论文写作辅助工具,简化了选题、文献检索至论文撰写的整个过程。通过简单设定,平台可快速生成高质量论文大纲和全文,配合图表、参考文献等一应俱全,同时提供开题报告和答辩PPT等增值服务,保障数据安全,有效提升写作效率和论文质量。

AI辅助写作AI工具AI论文工具论文写作智能生成大纲数据安全AI助手热门
博思AIPPT

博思AIPPT

AI一键生成PPT,就用博思AIPPT!

博思AIPPT,新一代的AI生成PPT平台,支持智能生成PPT、AI美化PPT、文本&链接生成PPT、导入Word/PDF/Markdown文档生成PPT等,内置海量精美PPT模板,涵盖商务、教育、科技等不同风格,同时针对每个页面提供多种版式,一键自适应切换,完美适配各种办公场景。

AI办公办公工具AI工具博思AIPPTAI生成PPT智能排版海量精品模板AI创作热门
潮际好麦

潮际好麦

AI赋能电商视觉革命,一站式智能商拍平台

潮际好麦深耕服装行业,是国内AI试衣效果最好的软件。使用先进AIGC能力为电商卖家批量提供优质的、低成本的商拍图。合作品牌有Shein、Lazada、安踏、百丽等65个国内外头部品牌,以及国内10万+淘宝、天猫、京东等主流平台的品牌商家,为卖家节省将近85%的出图成本,提升约3倍出图效率,让品牌能够快速上架。

下拉加载更多