• 一、概述
  • 二、远程写入特征
    • 2.1 整体结构
    • 2.2 重试机制
    • 2.3 内存使用
  • 三、参数
    • 3.1 capacity
    • 3.2 max_shards
    • 3.3 min_shards
    • 3.4 max_samples_per_send
    • 3.5 batch_send_deadline
    • 3.6 min_backoff
    • 3.7 max_backoff

一、概述

prometheus可以通过远程存储来解决自身存储的瓶颈,所以其提供了远程存储接口,并可以通过过配置文件进行配置(prometheus.yml)。一般情况下我们使用其默认的配置参数,但是为了满足特定的应用场景需要对其进行优化,本章节介绍可通过远程写入配置使用的调整参数,如下所示:

 # The URL of the endpoint to send samples to.
url: <string> # Timeout for requests to the remote write endpoint.
[ remote_timeout: <duration> | default = 30s ] # List of remote write relabel configurations.
write_relabel_configs:
[ - <relabel_config> ... ] # Sets the `Authorization` header on every remote write request with the
# configured username and password.
# password and password_file are mutually exclusive.
basic_auth:
[ username: <string> ]
[ password: <string> ]
[ password_file: <string> ] # Sets the `Authorization` header on every remote write request with
# the configured bearer token. It is mutually exclusive with `bearer_token_file`.
[ bearer_token: <string> ] # Sets the `Authorization` header on every remote write request with the bearer token
# read from the configured file. It is mutually exclusive with `bearer_token`.
[ bearer_token_file: /path/to/bearer/token/file ] # Configures the remote write request's TLS settings.
tls_config:
[ <tls_config> ] # Optional proxy URL.
[ proxy_url: <string> ] # Configures the queue used to write to remote storage.
queue_config:
# Number of samples to buffer per shard before we block reading of more
# samples from the WAL. It is recommended to have enough capacity in each
# shard to buffer several requests to keep throughput up while processing
# occasional slow remote requests.
[ capacity: <int> | default = 500 ]
# Maximum number of shards, i.e. amount of concurrency.
[ max_shards: <int> | default = 1000 ]
# Minimum number of shards, i.e. amount of concurrency.
[ min_shards: <int> | default = 1 ]
# Maximum number of samples per send.
[ max_samples_per_send: <int> | default = 100]
# Maximum time a sample will wait in buffer.
[ batch_send_deadline: <duration> | default = 5s ]
# Initial retry delay. Gets doubled for every retry.
[ min_backoff: <duration> | default = 30ms ]
# Maximum retry delay.
[ max_backoff: <duration> | default = 100ms ]

二、远程写入特征

我们本节主要探讨queue_config部分参数(其它参数比较简单,一看就知道什么意思,没有可优化的地方)。

2.1 整体结构

每个远程写入目标都会启动一个内存写队列(shards),这个队列从WAL中缓存数据(关于WAL可以参考存储部分:https://github.com/prometheus/prometheus/blob/master/docs/storage.md,原理类似于hbase中的WAL),通过队列去将指标数据写到有远程存储服务中,数据流如下所示:

        |-->  queue (shard_1)   --> remote endpoint
WAL --|--> queue (shard_...) --> remote endpoint
|--> queue (shard_n) --> remote endpoint

2.2 重试机制

这需要注意的是,当一个分片备份并填满队列时,Prometheus将阻止从WAL中读取数据到任何分片。(关于这点就涉及到对以上参数优化,后面参数capacity部分讲解)

远程端点写入失败会进行重试操作,并且保证数据不会丢失,除非远程端点保持关闭状态超过2小时,因为2小时后,WAL将被压缩,尚未发送的数据将丢失。重试时间见下面参数:min_backoff和max_backoff。

2.3 内存使用

使用远程写入会增加Prometheus的内存占用量。大多数用户报告的内存使用量增加了约25%,但这取决于数据的形状。对于WAL中的每个系列,远程写代码都会缓存系列ID到标签值的映射,从而显着增加内存使用率。

除了系列缓存之外,每个分片及其队列还会增加内存使用量。分片内存与number of shards * (capacity + max_samples_per_send)成正比。当进行优化调整时,请考虑减少max_shards增加的数量,同时提高capacitymax_samples_per_send参数的大小从而避免无意间耗尽内存。默认capacity和 max_samples_per_send的取值将使得每每个shard使用内存小于100kb。

三、参数

3.1 capacity

定义:每个内存队列(shard:分片)的容量。

一旦WAL被阻塞(造成阻塞的原因请看2.1),就无法将样本附加到任何分片,并且所有吞吐量都将停止。所以在大多数情况下,单个队列容量应足够打以避免阻塞其他分片,但是太大的容量可能会导致过多的内存消耗,并导致重新分片期间清除队列的时间更长。

容量建议:将容量设置为3-10倍max_samples_per_send

3.2 max_shards

顾名思义,最大的分片数(即队列数),也可以理解为远程写的并行度。peometheus远程写的时候会使用所有的分片,只有在写队列落后于远程写的速度,使用的队列数会达到max_shards,目的在于提高远程写的吞吐量。

PS:在操作过程中,Prometheus将根据传入的采样率,未发送的未处理样本数以及发送每个样本所花费的时间,连续计算要使用的最佳分片数。(实际的分片数是动态调整的

3.3 min_shards

最小分片配置Prometheus使用的最小分片数量,并且是远程写入开始时使用的分片数量。如果远程写入落后,Prometheus将自动扩大分片的数量,因此大多数用户不必调整此参数。但是,增加最小分片数将使Prometheus在计算所需分片数时避免在一开始就落后。

3.4 max_samples_per_send

定义:每次远程写发送的最大指标数量,即批处理;

这个值依赖于远程存储系统,对于一些系统而言,在没有显著增加延迟的情况下发送更多指标数据而运行良好,然而,对于另外一些系统而言,每次请求中发送大量指标数据可能导致其出现故障,使用的默认值是适用于绝大多数系统的。

3.5 batch_send_deadline

定义:单一分片批量发送指标数据的最大等待时间;
即使排队的分片尚未达到max_samples_per_send,也会发送请求。 对于对延迟不敏感的小批量系统,可以增加批量发送的截止时间,以提高请求效率。

3.6 min_backoff

定义:远程写失败的最小等待时间;

min_backoff是第一次的重试等待时间,第二次等待时间是其2倍,以此类推,直到max_backoff的值;

3.7 max_backoff

定义:远程写失败的最大等待时间;

参考文档:https://prometheus.io/docs/practices/remote_write/

prometheus远程写参数优化的更多相关文章

  1. linux下TCP/IP及内核参数优化调优(转)

    Linux下TCP/IP及内核参数优化有多种方式,参数配置得当可以大大提高系统的性能,也可以根据特定场景进行专门的优化,如TIME_WAIT过高,DDOS攻击等等. 如下配置是写在sysctl.con ...

  2. Windows下tcp参数优化

    Windows系统下的TCP参数优化2013-04-25      0 个评论       作者:最初的幸福ever收藏     我要投稿Windows系统下的TCP参数优化 TCP连接的状态与关闭方 ...

  3. MySQL配置文件my.cnf参数优化和中文详解

    Mysql参数优化对于新手来讲,是比较难懂的东西,其实这个参数优化,是个很复杂的东西,对于不同的网站,及其在线量,访问量,帖子数量,网络情况,以及机器硬件配置都有关系,优化不可能一次性完成,需要不断的 ...

  4. Limit参数优化MySQL查询的方法

    在做一些查询时,总希望能避免数据库引擎做全表扫描,因为全表扫描时间长,而且其中大部分扫描对客户端而言是没有意义的.那么,在mysql中有那些方式是可以避免全表扫面?除了通过使用索引列或分区等方式来进行 ...

  5. MySQL参数优化

    目前针对MySQL数据库进行了一些参数优化,具体如下: my.ini / my.cnf 参数说明 #使用查询缓存 query_cache_size=100M                     # ...

  6. jvm参数优化

    一.HotSpot JVM 提供了三类参数 现在的JVM运行Java程序(和其它的兼容性语言)时在高效性和稳定性方面做的非常出色.例如:自适应内存管理.垃圾收集.及时编译.动态类加载.锁优化等.虽然有 ...

  7. Windows系统下的TCP参数优化

    1. TCP连接的状态 首先介绍一下TCP连接建立与关闭过程中的状态.TCP连接过程是状态的转换,促使状态发生转换的因素包括用户调用.特定数据包以及超时等,具体状态如下所示: CLOSED:初始状态, ...

  8. Linux中MySQL配置文件my.cnf参数优化

    MySQL参数优化这东西不好好研究还是比较难懂的,其实不光是MySQL,大部分程序的参数优化,是很复杂的.MySQL的参数优化也不例外,对于不同的需求,还有硬件的配置,优化不可能又最优选择,只能慢慢的 ...

  9. Windows系统下的TCP参数优化(注册表\TCPIP\Parameters)

    转自:https://blog.csdn.net/libaineu2004/article/details/49054261 Windows系统下的TCP参数优化   TCP连接的状态与关闭方式及其对 ...

随机推荐

  1. acedCommandS 实现pedit命令

    acedCommandS(RTSTR, _T("PEDIT"),                RTSTR, _T("M"),                R ...

  2. FPGA小白学习之路(5)clk为什么要用posedge,而不用negedge(转)

    clk为什么要用posedge,而不用negedge 转自:http://www.cnblogs.com/dangxia/archive/2012/03/07/2383744.html Verilog ...

  3. Requests功能整理

    import requests # GET r = requests.get('https://api.github.com/events') # POSTr = requests.post('htt ...

  4. unittest实战(二):用例编写

    # coding:utf-8import unittestfrom selenium import webdriverimport timefrom ddt import ddt, data, unp ...

  5. APScheduler使用总结

    安装 pip install apscheduler APScheduler组件 1.triggers(触发器) 触发器中包含调度逻辑,每个作业都由自己的触发器来决定下次运行时间.除了他们自己初始配置 ...

  6. html/css系列 BFC

    本文详情:https://www.cnblogs.com/chen-... 第一种 BFC中的盒子对齐 <div class="container"> <div ...

  7. 16 搭建Spring Data JPA的开发环境

    使用Spring Data JPA,需要整合Spring与Spring Data JPA,并且需要提供JPA的服务提供者hibernate,所以需要导入spring相关坐标,hibernate坐标,数 ...

  8. 7种你应该知道的JavaScript常见的错误

    转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 原文出处:https://blog.bitsrc.io/types-of-native-errors-in- ...

  9. 打开ElasticSearch、kibana、logstash的正确方式

    作者:玩世不恭的Coder时间:2020-03-08说明:原创不易,本文为原创文章,未经允许不可转载,转载前请联系作者 打开ElasticSearch.kibana.logstash的正确方式 前言一 ...

  10. 【沫沫金】使用Serv-U FTP服务,搭建文件服务器

    内网文件服务器安装Serv-U FTP 链接: https://pan.baidu.com/s/1G51D1enLqZCUhnprnjAITw 提取码: snah Java Web工程,引入 comm ...