• HTTP高并发调优小记


    tomcat服务层

    1.修改server.xml

    <Connector port="8088" protocol="HTTP/1.1"
                   maxThreads="1000"
                   connectionTimeout="60000"
                   acceptCount="1100"
                   redirectPort="8443" />

    2.修改catalina.bat

    set JAVA_OPTS=-Xms1024m -Xmx2048m

    Java应用层-Httpclient

    1.修改连接池的连接数

    static {
        LayeredConnectionSocketFactory sslsf = null;
        try {
          sslsf = new SSLConnectionSocketFactory(SSLContext.getDefault());
        } catch (NoSuchAlgorithmException e) {
          logger.error("创建SSL连接失败");
        }
        Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
            .register("https", sslsf)
            .register("http", new PlainConnectionSocketFactory())
            .build();
        cm = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
        // 设置连接池最大连接数800
        cm.setMaxTotal(800);
        // 设置最大路由数10
        cm.setDefaultMaxPerRoute(10);
      }

    2.设置失败重试次数

    /**
       * getHttpClient
       * <p>通过连接池管理创建CloseableHttpClient</p>
       * @return
       */
      private static CloseableHttpClient getHttpClient() {
        CloseableHttpClient httpClient = HttpClients.custom()
            .setConnectionManager(cm)
            .setUserAgent(properties.getProperty("userAgent"))
            // 失败重连5次
            .setRetryHandler(new DefaultHttpRequestRetryHandler(5, false))
            .build();
        return httpClient;
      }

    3.设置连接超时时长

    /**
       * config
       * <p>普通请求配置</p>
       * @param httpRequestBase
       */
      private static void config(HttpRequestBase httpRequestBase) {
        httpRequestBase.setHeader("Accept-Encoding", "gzip,deflate");
        // 配置请求的超时设置
        RequestConfig requestConfig = RequestConfig.custom()
            .setConnectionRequestTimeout(3000)
            .setConnectTimeout(3000)
            .setSocketTimeout(3000)
            .build();
        httpRequestBase.setConfig(requestConfig);
      }
  • 相关阅读:
    Axis,axis2,Xfire以及cxf对比 (转)
    客户端调用服务器端三种方式
    webservice发送数据,取数据的方式
    强制关闭myeclipse出现的问题
    取当前系统的上月时间
    oracle 报Ora-01008错误:oracle 并非所有变量都已绑定的原因.TO_number();动态执行select..into..语句时
    ResultSetMetaData rsmd = rs.getMetaData()是什么意思?
    概率质量函数:怀孕周期的PMF
    Python 正则表达式
    TF-IDF
  • 原文地址:https://www.cnblogs.com/azcode/p/7910361.html
Copyright © 2020-2023  润新知