zoukankan      html  css  js  c++  java
  • Tomcat下WebSocket最大连接数测试

    WebSocket现在很常用,想要测试tomcat的最大连接数,今天试了一个可行的办法和配置(之前是用全公司的设备一起来测试的,真机环境的测试收到网络的影响很大,其实真实环境应用中,网络才是websocket的最大瓶颈)

    废话不多说~

    1.Tomcat需要设置的地方(很多人从网上找的配置试了不可行):

    1.1修改catalina.sh或者catalina.bat文件,加上这句话(JAVA_OPTS="-server -Xms2048m -Xmx2048m -Xmn512m")。

    1.2修改conf下server.xml,    

                <Connector port="8180" protocol="org.apache.coyote.http11.Http11NioProtocol" connectionTimeout="20000" acceptCount="4000" 

                      maxThreads="500" maxConnections="4000" enableLookups="false"  redirectPort="8443" />

    上面的设置1.1影响最终你的最大连接数,1.2的maxConnections就是最大连接数,有时候觉得设置无效,请把1.1的内存一起调大!

     网上的测试结果:

    首先tomcat最大线程数默认肯定到不了几千,所以我们需要调tomcat最大线程数及运行内存。我这边最大运行内存3个g,最大线程调到5k的情况下,3k个client同时在线是没问题的。再者大家注意下linux操作系统本身有些涉及到tcp连接的配置也可能需要修改。

    心跳间隔最好维持在4分半,以便兼容所有浏览器。详细见《http://m.blog.csdn.net/shangmingtao/article/details/75810099》

    压力测试类:

    package org.springframework.samples.websocket.echo2;
    
    import java.net.URI;
    
    import javax.websocket.ClientEndpoint;
    import javax.websocket.ContainerProvider;
    import javax.websocket.Session;
    import javax.websocket.WebSocketContainer;
    
    @ClientEndpoint
    public class WebSocketTest {
    
        private String deviceId;
    
        private Session session;
    
        public WebSocketTest() {
        }
    
        public WebSocketTest(String deviceId) {
            this.deviceId = deviceId;
        }
    
        protected boolean start() {
            WebSocketContainer container = ContainerProvider.getWebSocketContainer();
            String uri = "ws://localhost:8080/spring-websocket-test/demo2/client-" + deviceId;
            System.out.println("Connecting to " + uri);
            try {
                session = container.connectToServer(WebSocketTest.class, URI.create(uri));
                System.out.println("count: " + deviceId);
            } catch (Exception e) {
                e.printStackTrace();
                return false;
            }
            return true;
        }
    
        public static void main(String[] args) {
            int size = Integer.parseInt(args[0]);
            for (int i = 1; i < size; i++) {
                WebSocketTest wSocketTest = new WebSocketTest(String.valueOf(i));
                if (!wSocketTest.start()) {
                    System.out.println("测试结束!");
                    break;
                }
            }
            System.out.println("===========客户端启动的线程为:="+size);
        }
    }

    jsp页面:

    <%@page import= "org.springframework.samples.websocket.echo2.*"%>
    <%
    String size=request.getParameter("size");
    String[] parms = {size};
    WebSocketTest te=new WebSocketTest();
    te.main(parms);
    %>
    <h1>ok</h1> 

    结果:

  • 相关阅读:
    How to install VXDIAG Honda, Toyota and JLR SDD software
    16% off MPPS V16 ECU tuning tool for EDC15 EDC16 EDC17
    Cummins INSITE locked and ask for verification code
    How to use BMW Multi Tool 7.3 to replace lost key for BMW X1
    Bleed Brake Master Cylinder with Intelligent Tester IT2
    Porsche Piwis Tester II “No VCI has been detected”,how to do?
    Creader VIII VS. Creader VII+
    How to solve GM MDI cannot complete the installation
    汽车OBD2诊断程序开发 (原文转载,思路很清晰!)
    汽车节温器单片机开发思路
  • 原文地址:https://www.cnblogs.com/duanxz/p/5146449.html
Copyright © 2011-2022 走看看