zk maxClientCnxns参数
在zk模板配置文件中有:
# the maximum number of client connections.
# increase this if you need to handle more clients
maxClientCnxns=60
这个配置的作用就是:一个ip所对应的客户机,只能和zk服务器维持60个连接。
以NIOServerCnxnFactory为例:
public abstract class ServerCnxnFactory {
//存放zk所有连接
protected final HashSet<ServerCnxn> cnxns = new HashSet<ServerCnxn>();
}
public class NIOServerCnxnFactory extends ServerCnxnFactory implements Runnable {
//客户端ip -> 客户端的连接集合
final HashMap<InetAddress, Set<NIOServerCnxn>> ipMap = new HashMap<InetAddress, Set<NIOServerCnxn>>( );
//获取指定ip的连接数
private int getClientCnxnCount(InetAddress cl) {
// The ipMap lock covers both the map, and its contents
// (that is, the cnxn sets shouldn't be modified outside of
// this lock)
synchronized (ipMap) {
Set<NIOServerCnxn> s = ipMap.get(cl);
if (s == null) return 0;
return s.size();
}
}
public void run() {
while (!ss.socket().isClosed()) {
try {
selector.select(1000);
Set<SelectionKey> selected;
synchronized (this) {
selected = selector.selectedKeys();
}
ArrayList<SelectionKey> selectedList = new ArrayList<SelectionKey>(
selected);
Collections.shuffle(selectedList);
for (SelectionKey k : selectedList) {
if ((k.readyOps() & SelectionKey.OP_ACCEPT) != 0) {
SocketChannel sc = ((ServerSocketChannel) k
.channel()).accept();
InetAddress ia = sc.socket().getInetAddress();
//获取客户端连接数
int cnxncount = getClientCnxnCount(ia);
//单个客户端连接数超过限制
if (maxClientCnxns > 0 && cnxncount >= maxClientCnxns){
LOG.warn("Too many connections from " + ia
+ " - max is " + maxClientCnxns );
sc.close();
} else {
LOG.info("Accepted socket connection from "
+ sc.socket().getRemoteSocketAddress());
sc.configureBlocking(false);
SelectionKey sk = sc.register(selector,
SelectionKey.OP_READ);
NIOServerCnxn cnxn = createConnection(sc, sk);
sk.attach(cnxn);
addCnxn(cnxn);
}
} else if ((k.readyOps() & (SelectionKey.OP_READ | SelectionKey.OP_WRITE)) != 0) {
NIOServerCnxn c = (NIOServerCnxn) k.attachment();
c.doIO(k);
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Unexpected ops in select "
+ k.readyOps());
}
}
}
selected.clear();
} catch (RuntimeException e) {
LOG.warn("Ignoring unexpected runtime exception", e);
} catch (Exception e) {
LOG.warn("Ignoring exception", e);
}
}
closeAll();
LOG.info("NIOServerCnxn factory exited run method");
}
}
tips: 关心这个参数,是因为之前有人上线时,客户端连接数超过了默认值,导致无法建立连接。
zk maxClientCnxns参数的更多相关文章
- dubbo、zookeeper心跳相关参数解析与测试
dubbo consumer和provider的心跳机制 dubbo客户端和dubbo服务端之间存在心跳,目的是维持provider和consumer之间的长连接.由dubbo客户端主动发起,可参见d ...
- Zookeeper的基本原理(zk架构、zk存储结构、watch机制、独立安装zk、集群间同步复制)
1.Hbase集群的高可用性与伸缩性 HBase可以实现对Regionserver的监控,当个别Regionserver不可访问时,将其负责的分区分给其他Regionsever,其转移过程较快,因为只 ...
- 基于ZooKeeper,Spring设计实现的参数系统
一.简介 基于ZooKeeper服务端.ZooKeeper Java客户端以及Spring框架设计的用于系统内部进行参数维护的系统. 二.设计背景 在我们日常开发的系统内部,开发过程中最常见的一项工作 ...
- Zookeeper运维问题集锦
实际工作中用到Zookeeper集群的地方很多, 也碰到过各种各样的问题, 在这里作个收集整理, 后续会一直补充; 其中很多问题的原因, 解决方案都是google而来, 这里只是作次搬运工; 其实很多 ...
- Zookeeper开发常见问题
背景与目的 Zookeeper开发过程中遇到一些常见问题,为了后续开发不犯同样的错误,总结一下此类问题,并进行分析和解决. 适合人员 主要适合zookeeper开发.测试及运维相关人员. 问题与解决 ...
- Mesos+Zookeeper+Marathon+Docker环境搭建
相关理论请参考:https://www.cnblogs.com/Bourbon-tian/p/7155054.html,本文基于https://www.cnblogs.com/Bourbon-tian ...
- kafka概念
一.结构与概念解释 1.基础概念 topics: kafka通过topics维护各类信息. producer:发布消息到Kafka topic的进程. consumer:订阅kafka topic进程 ...
- 大数据平台常见异常-zookeeper
本文主要阐述大数据平台环境zookeeper常见异常和解决方案 1.Connection reset by peer异常 异常说明 我们现在项目有个任务OneMinuteDataSync是用spark ...
- 深度学习之循环神经网络(RNN)
循环神经网络(Recurrent Neural Network,RNN)是一类具有短期记忆能力的神经网络,适合用于处理视频.语音.文本等与时序相关的问题.在循环神经网络中,神经元不但可以接收其他神经元 ...
随机推荐
- Python3基础 list 查看filter()返回的对象
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- STM32定时器的预装载寄存器与影子寄存器之间的关系【转】
首先转载: STM32定时器的预装载寄存器与影子寄存器之间的关系 本文的说明依据STM32参考手册(RM0008)第10版:英文:http://www.st.com/stonline/produc ...
- Git 基础 —— 常用命令
Git 基础学习系列 Git 基础 -- 安装 配置 别名 对象 Git 基础 -- 常用命令 Git 基础 -- 常见使用场景 Git基础 -- Github 的使用 git init 创建 Git ...
- luogu P4396 [AHOI2013]作业
目录 题目 思路 错误&&傻叉 代码 题目 luogu 思路 每次都是插入比之前所有数字大的数,所以之前的答案就不会改变 用fhq-treap求出原序列,然后用树状数组依次算出每个值得 ...
- Linux 安装 mysql 转 http://www.cnblogs.com/fnlingnzb-learner/p/5830622.html
到mysql官网下载mysql编译好的二进制安装包,在下载页面Select Platform:选项选择linux-generic,然后把页面拉到底部,64位系统下载Linux - Generic (g ...
- hdu 1005 矩阵快速幂
#include<iostream> #include<cstdio> #include<cmath> #include<string> #includ ...
- WPF基础学习笔记整理 (三) x命名空间
“x命名空间”中x是XAML的首字母,用来引导XAML编译器把XAML代码编译成CLR代码.下边的图片表格列举了该命名空间部分成员及其作用,更多请见URL:https://msdn.microsoft ...
- ros 启动launch文件,附带参数
roslaunch cartographer_ros cartographer_ref.launch resolution:=0.07 #下面是cartographer_ref.launch的内容 & ...
- 《F4+2》β冲刺第二天
β冲刺第二天 1.每个成员今日完成的任务: 马仲山:系统代码和开发总结文档的完善 马婧(12):完善需求文档 马婧(13):完善设计文档 马世芳:对部分功能实现进行测试 张俊逸:针对测试出现的问题完善 ...
- spring boot 开发 org.springframework.context.ApplicationContextException: Unable to start web server;
Error starting ApplicationContext. To display the conditions report re-run your application with 'de ...