转载请注明地址http://www.cnblogs.com/dongxiao-yang/p/5217754.html

Starting in 0.9, the Kafka cluster has the ability to enforce quotas on produce and fetch requests. Quotas are basically byte-rate thresholds defined per client-id. A client-id logically identifies an application making a request. Hence a single client-id can span multiple producer and consumer instances and the quota will apply for all of them as a single entity i.e. if client-id="test-client" has a produce quota of 10MB/sec, this is shared across all instances with that same id.

从0.9版本开始,kafka集群新增了针对生产和消费请求进行配额(quotas)控制的能力。Quota基本上是一个单client-id的数据byte速率的门槛值的概念。逻辑上一个client-id代表了一个产生请求的应用程序。一个client-id理论上可以拥有多个producer或者consumer实例,qouta会把这些实例当做一整个个体来对待。假如一个client-id为“test-client”的程序quota设置为10MB/s,拥有相同id的实例会共享这个配额。

It is possible for producers and consumers to produce/consume very high volumes of data and thus monopolize broker resources, cause network saturation and generally DOS other clients and the brokers themselves. Having quotas protects against these issues and is all tbe more important in large multi-tenant clusters where a small set of badly behaved clients can degrade user experience for the well behaved ones. In fact, when running Kafka as a service this even makes it possible to enforce API limits according to an agreed upon contract.

生产/消费者有可能会产生非常高的数据吞吐并因此抢占了broker服务器的资源,造成网络饱和并且通常会DoS掉其他client的连接和broker服务器本身。加入quota机制可以预防上述情况的发生,更可以避免集群在多用户的场景下由于个别客户端的异常流量影响其余正常客户端的使用(就是一颗老鼠屎坏了一锅汤的意思)。其实,由于kafka本来就是作为一个后台服务运行的,通过api接口强制进行限制约定是很可行的办法。

By default, each unique client-id receives a fixed quota in bytes/sec as configured by the cluster (quota.producer.default, quota.consumer.default). This quota is defined on a per-broker basis. Each client can publish/fetch a maximum of X bytes/sec per broker before it gets throttled. We decided that defining these quotas per broker is much better than having a fixed cluster wide bandwidth per client because that would require a mechanism to share client quota usage among all the brokers. This can be harder to get right than the quota implementation itself!

默认情况下,每一个单独的client-id对应一份集群配置的固定quta速度(默认配置在quota.producer.default, quota.consumer.default)。quota是一个被定义到每台broker粒度的概念。每个client在达到限速前可以与单台broker产生最大为X bytes/sec的写/读流量请求。决定将quota定义到每台broker粒度比设置一个固定的全集群粒度的带宽概念更合适,这样可以省去一个在集群broker间协调quota的机制。这个协调机制可能比quota机制本身的实现更为麻烦!

How does a broker react when it detects a quota violation? In our solution, the broker does not return an error rather it attempts to slow down a client exceeding its quota. It computes the amount of delay needed to bring a guilty client under it's quota and delays the response for that time. This approach keeps the quota violation transparent to clients (outside of client side metrics). This also keeps them from having to implement any special backoff and retry behavior which can get tricky. In fact, bad client behavior (retry without backoff) can exacerbate the very problem quotas are trying to solve.

broker在发现超出quota的情况下会如何处理?我们目前的处理方法是,broker并不会返回错误信息而是会尝试降低客户端的速度。broker计算出将客户端速度限制在quota以下需要的delay时间然后在response时先delay这么多时间再响应。这种机制基本实现将quota限速功能对客户端透明化(无需客户端一侧的配置),同时也避免了客户端需要实现的复杂麻烦的backoff和retry的逻辑。事实上,异常的客户端行为(没有回退机制的重试)可能将quota想要解决的问题更加恶化。

Client byte rate is measured over multiple small windows (for e.g. 30 windows of 1 second each) in order to detect and correct quota violations quickly. Typically, having large measurement windows (for e.g. 10 windows of 30 seconds each) leads to large bursts of traffic followed by long delays which is not great in terms of user experience.

客户端的byte速率是通过多个小的窗口抽样(比如说每秒抽样30次)来准确并迅速的发现quota超限的情况。通常来说,长时间的抽样窗口(比如30秒抽样10次)会由于延迟较大可能会发生流量拥堵的状况,这会影响用户体验。

Quota overrides(quota 重设)

It is possible to override the default quota for client-ids that need a higher (or even lower) quota. The mechanism is similar to the per-topic log config overrides. Client-id overrides are written to ZooKeeper under/config/clients. These overrides are read by all brokers and are effective immediately. This lets us change quotas without having to do a rolling restart of the entire cluster. See here for details.

可以修改某个客户端默认的quota,方法与每个topic的config重设类似。客户端的设置位于zookeeper服务/config/clients路径下。这个改动会被所有broker读取并且立即生效。

这可以使我们无需滚动重启整个集群就可以改变quota。参考如下连接 here

kafka配额控制的更多相关文章

  1. 【甘道夫】Apache Hadoop 2.5.0-cdh5.2.0 HDFS Quotas 配额控制

    前言 HDFS为管理员提供了针对文件夹的配额控制特性,能够控制名称配额(指定文件夹下的文件&文件夹总数),或者空间配额(占用磁盘空间的上限). 本文探究了HDFS的配额控制特性,记录了各类配额 ...

  2. Hadoop生态圈-kafka事务控制以及性能测试

    Hadoop生态圈-kafka事务控制以及性能测试 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任.

  3. docker容器资源配额控制

    转自:http://blog.csdn.net/horsefoot/article/details/51731543 文/ 天云软件 容器技术团队 Docker通过cgroup来控制容器使用的资源配额 ...

  4. docker容器资源配额控制_转

    转自:docker容器资源配额控制 ■ 文/ 天云软件 容器技术团队 docker通过cgroup来控制容器使用的资源配额,包括CPU.内存.磁盘三大方面,基本覆盖了常见的资源配额和使用量控制. cg ...

  5. 使用 Admission Webhook 机制实现多集群资源配额控制

    1 要解决的问题 集群分配给多个用户使用时,需要使用配额以限制用户的资源使用,包括 CPU 核数.内存大小.GPU 卡数等,以防止资源被某些用户耗尽,造成不公平的资源分配. 大多数情况下,集群原生的 ...

  6. 关于Kafka配额的讨论(1)

    Kafka自0.9.0.0版本引入了配额管理(quota management),旨在broker端对clients发送请求进行限流(throttling).目前Kafka支持两大类配额管理: 网络带 ...

  7. Kafka配额讨论(流量限制)

    Kafka自0.9.0.0版本引入了配额管理(quota management),旨在broker端对clients发送请求进行限流(throttling).目前Kafka支持两大类配额管理: 网络带 ...

  8. 关于Kafka配额的讨论(2)

    继续前一篇的讨论.前文中提到了两大类配额管理:基于带宽的以及基于CPU线程使用时间的.本文着重探讨基于CPU线程时间的配额管理. 定义 这类配额管理被称为请求配额(request quota),管理起 ...

  9. kafka中的配额管理(限速)机制

    kafka支持配额管理,从而可以对Producer和Consumer的produce&fetch操作进行流量限制,防止个别业务压爆服务器.本文主要介绍如何使用kafka的配额管理功能. 1 K ...

随机推荐

  1. QuickSort 递归 分治

    QuickSort 参考<算法导论>,<C程序设计语言> #include<stdio.h> void swap(int v[], int i, int j); v ...

  2. 及其简易的js 倒计时插件

    网上虽然有很多漂亮的且很实用的倒计时插件,但是,对于需要自己定制的倒计时来讲确实一个不小的障碍.最近我们的英语在线教育产品,在线考试模块需要用到一个计时器,所以顺势开发了一个自己的及时器. http: ...

  3. php模块参考

    <?php //数据库连接类 class ConnDB{ var $dbtype; var $host; var $user; var $pwd; var $dbname; //构造方法 fun ...

  4. Linux内存映射(mmap)系列(1)

    看到同事的代码中出现了mmap.所以自己私下学习学习,研究研究..... http://www.cnblogs.com/lknlfy/archive/2012/04/27/2473804.html ( ...

  5. 项目管理Point

    1.项目管理流程 在设计阶段需要提交的成果物:类图设计(每个方法要有成形的SQL),页面设计,数据库设计,思路:需求分析->用户故事->客户确认(前三步是个迭代过程)->类图设计(了 ...

  6. 学习Swift--方法

    方法 方法是与某些特定类型相关联的函数.类.结构体.枚举都可以定义实例方法:实例方法为给定类型的实例封装了具体的任务与功能.类.结构体.枚举也可以定义类型方法:类型方法与类型本身相关联.类型方法与 O ...

  7. C51应用 Modbs Rtu协议实现与KEPServerEx 通信

    最近一客户要求使用STC12C5A60S2实现Modbus Rtu协议与KEPServerEx V4.0软件通信,采集单片机P2口每位的状态,设置P0口每位的状态,实现三路AD转换其中一路采集的是C0 ...

  8. Hibernate中的一对一关系详解(1)

    A:先讲讲一对一的关系(欲知其他关系,请看下篇) a:主键关联的一对一关系 一对一关系一般用主键关联,也就是说用主键值来维护两者的关系,一个表的主键存放另一个表的主键值.例如在员工与帐号中,我们取员工 ...

  9. 完美解决 Phonegap jQeuryMobile 闪屏 问题

    在切换page或者弹出dialog时,会出现闪屏情况,综合网络上各种方法,得出以下方法可完美解决: 1.首先界面页面切换闪屏: 在加载jQuery后,加载jQuery Mobiel之前,插入js语句进 ...

  10. A simple Gaussian elimination problem.

    hdu4975:http://acm.hdu.edu.cn/showproblem.php?pid=4975 题意:给你一个n*m的矩阵,矩阵中的元素都是0--9,现在给你这个矩阵的每一行和每一列的和 ...