• 一、概述
  • 二、远程写入特征
    • 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. Job for network.service failed because the control process exited with error code问题

    Job for network.service failed because the control process exited with error code问题 因为是克隆的,所以需要重新修改静 ...

  2. C#编程_单线程IP地址解析

    单线程IP地址解析 目标程序 界面如下图 ​ 设计方法:完成单个IP地址解析,循环调用方法,完成扫描. 注意用stopwatch计算时间. 实现思路 先知道怎么解析一个单个的IP地址. 用循环的方法解 ...

  3. Typora[MarkDown编辑器]+(PicGo+Github+JsDelivr)[个人图床] ,开启你的高效创作

    使用Typora搭配Picgo开启你的高效创作 0x00 一切都要从MarkDown说起 富文本语言的弊端 平常我们最常用的写作工具,无非是富文本编辑器中的代表--微软家的Office Word.这种 ...

  4. IDEA非maven项目怎么添加jar包

    今天本人给大家讲解一下在使用Tomcat启动后,报找不到JAR包的问题,那么如何在IDEA中添加jar包,下面请看,如有不对的或者讲的不好的可以多多提出,我会进行相应的更改,先提前感谢提出意见的各位了 ...

  5. linux 安装 memcached

    1.Linux系统安装memcached,首先要先安装libevent库. yum install libevent libevent-deve 2.安装memcached yum install - ...

  6. vue环境搭建过程中,npm权限不足问题

    今天在用git bash进行全局安装vue-cli的时候,报错: 必须以管理员权限进行安装才行.所以用cmd命令工具,点击右键命令提示符cmd--------以管理员身份运行--------cd进入到 ...

  7. MongoDB复制集概念架构浅析

    一.复制集的作用 (1) 高可用 防止设备(服务器.网络)故障. 提供自动failover 功能. 技术来保证数 (2) 灾难恢复 当发生故障时,可以从其他节点恢复. (3) 功能隔离 用于分析.报表 ...

  8. R的plotmath

    plotmath plotmath {grDevices}:Mathematical Annotation in R # Copyright (C) 2002-2016 The R Core Team ...

  9. 数据结构 - List 接口

    简介 List接口继承自Collection接口,是Collection三大延伸接口之一.List中的元素都是有序的,并且都支持用索引访问.同时List中的元素允许重复. public interfa ...

  10. C++ 结构体sturct练习

    #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> struct Student { ];// 姓名 int id; //id int a ...