分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 前端开发

HTTP高并发调优小记

发布时间:2023-09-06 01:27责任编辑:沈小雨关键词:高并发

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); ?}

HTTP高并发调优小记

原文地址:http://www.cnblogs.com/azcode/p/7910361.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved