在 jmeter 跑 2000 并发时,报错:


java.net.SocketException: Socket closed

at java.net.SocketInputStream.socketRead0(Native Method)

at java.net.SocketInputStream.socketRead(Unknown Source)

at java.net.SocketInputStream.read(Unknown Source)

at java.net.SocketInputStream.read(Unknown Source)

at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:137)

at org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:153)

at org.apache.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:282)

at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:138)

at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:56)

at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:259)

at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:163)

at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:165)

at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:273)

at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125)

at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:272)

at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)

at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)

at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)

at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)

at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)

at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.executeRequest(HTTPHC4Impl.java:832)

at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sample(HTTPHC4Impl.java:570)

at org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:67)

at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1231)

at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1220)

at org.apache.jmeter.threads.JMeterThread.doSampling(JMeterThread.java:622)

at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:546)

at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:486)

at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:253)

at java.lang.Thread.run(Unknown Source)


解决方法: linux 服务端连接数为 1024,连接数不够,需要重新设置:

vim   /etc/sysctl.conf

#自定义内核参数

net.ipv4.tcp_max_tw_buckets = 6000

net.ipv4.ip_local_port_range = 1024 65535(端口数上限修改为 65535)

net.ipv4.tcp_tw_recycle = 1  (由0修改为1)

net.ipv4.tcp_tw_reuse = 1   (由0修改为1)

#net.ipv4.tcp_syncookies = 1

net.core.somaxconn = 65535

net.core.netdev_max_backlog = 262144

net.ipv4.tcp_max_syn_backlog = 262144

net.ipv4.tcp_timestamps = 1

net.ipv4.tcp_synack_retries = 1

net.ipv4.tcp_syn_retries = 1

net.ipv4.tcp_fin_timeout = 30

net.ipv4.tcp_keepalive_time = 60

解释一下这两个参数:

net.ipv4.tcp_tw_recycle:表示开启连接重用

net.ipv4.tcp_tw_reuse:表示开启连接回收

sysctl -p    或   /sbin/sysctl -p   (修改后生效)

再用2000用户进行压测,问题解决!