一.前言

因为公司需要,所以在不断尝试使用JMeter压力测试工具中,遇到了一些高并发的问题,以及一些坑,在此记录一下,在此说明一下本人是Java开发程序员。

二.Nginx配置

1.worker_processes 8;

nginx 进程数,建议按照cpu 数目来指定,一般为它的倍数 (如,2个四核的cpu计为8)。

2.worker_rlimit_nofile 65535;

这个指令是指当一个nginx 进程打开的最多文件描述符数目,理论值应该是最多打开文
件数(ulimit -n)与nginx 进程数相除,但是nginx 分配请求并不是那么均匀,所以最好与ulimit -n 的值保持一致。

3.worker_connections 65535;

每个进程允许的最多连接数, 理论上每台nginx 服务器的最大连接数为worker_processes*worker_connections。

ngnix.conf配置

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/user nginx;
#worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;worker_processes 4;
worker_rlimit_nofile 204800;events {worker_connections 262140;
}http {log_format  main  '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';access_log  /var/log/nginx/access.log  main;sendfile            on;tcp_nopush          on;tcp_nodelay         on;keepalive_timeout   65;types_hash_max_size 2048;include             /etc/nginx/mime.types;default_type        application/octet-stream;# Load modular configuration files from the /etc/nginx/conf.d directory.# See http://nginx.org/en/docs/ngx_core_module.html#include# for more information.include /etc/nginx/conf.d/*.conf;upstream fxqhttp {#ip_hash;server 192.168.0.226:8080;#1号服务器内网#server 118.31.75.83:8080;#1号服务器外网server 192.168.0.229:8080;#2号内网#server 121.196.194.188:8080;#2号服务器外网}server {listen       80 default_server;listen       [::]:80 default_server;server_name  _;root         /usr/share/nginx/html;# Load configuration files for the default server block.include /etc/nginx/default.d/*.conf;location /trainsys {proxy_pass http://fxqhttp;}error_page 404 /404.html;location = /40x.html {}error_page 500 502 503 504 /50x.html;location = /50x.html {}}# Settings for a TLS enabled server.
#
#    server {
#        listen       443 ssl http2 default_server;
#        listen       [::]:443 ssl http2 default_server;
#        server_name  _;
#        root         /usr/share/nginx/html;
#
#        ssl_certificate "/etc/pki/nginx/server.crt";
#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
#        ssl_session_cache shared:SSL:1m;
#        ssl_session_timeout  10m;
#        ssl_ciphers HIGH:!aNULL:!MD5;
#        ssl_prefer_server_ciphers on;
#
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#
#        location / {
#        }
#
#        error_page 404 /404.html;
#            location = /40x.html {
#        }
#
#        error_page 500 502 503 504 /50x.html;
#            location = /50x.html {
#        }
#    }}

三.tomcat配置

Tomcat 默认配置的最大请求数是 150,也就是说同时支持 150 个并发,当然了,也可以将其改大。请求越多分配给JVM的内存越多,CPU也会消耗的更多。接口请求也会随着并发的上来,接口响应速度就会变慢。

maxThreads: 最大并发数

acceptCount: 指定当所有可以使用的处理请求的线程数都被使用时,可以放到处理队列中的请求数,超过这个数的请求将不予处理

如果说maxThreads是250,acceptCount是100的话,请求到达了250个还可以有100请求在等待请求,如果350个以上请求直接不处理。

配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<!--Licensed to the Apache Software Foundation (ASF) under one or morecontributor license agreements.  See the NOTICE file distributed withthis work for additional information regarding copyright ownership.The ASF licenses this file to You under the Apache License, Version 2.0(the "License"); you may not use this file except in compliance withthe License.  You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.
-->
<!-- Note:  A "Server" is not itself a "Container", so you may notdefine subcomponents such as "Valves" at this level.Documentation at /docs/config/server.html-->
<Server port="8005" shutdown="SHUTDOWN"><Listener className="org.apache.catalina.startup.VersionLoggerListener" /><!-- Security listener. Documentation at /docs/config/listeners.html<Listener className="org.apache.catalina.security.SecurityListener" />--><!--APR library loader. Documentation at /docs/apr.html --><Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /><!-- Prevent memory leaks due to use of particular java/javax APIs--><Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" /><Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /><Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" /><!-- Global JNDI resourcesDocumentation at /docs/jndi-resources-howto.html--><GlobalNamingResources><!-- Editable user database that can also be used byUserDatabaseRealm to authenticate users--><Resource name="UserDatabase" auth="Container"type="org.apache.catalina.UserDatabase"description="User database that can be updated and saved"factory="org.apache.catalina.users.MemoryUserDatabaseFactory"pathname="conf/tomcat-users.xml" /></GlobalNamingResources><!-- A "Service" is a collection of one or more "Connectors" that sharea single "Container" Note:  A "Service" is not itself a "Container",so you may not define subcomponents such as "Valves" at this level.Documentation at /docs/config/service.html--><Service name="Catalina"><!--The connectors can use a shared executor, you can define one or more named thread pools--><!--<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"maxThreads="150" minSpareThreads="4"/>--><!-- A "Connector" represents an endpoint by which requests are receivedand responses are returned. Documentation at :Java HTTP Connector: /docs/config/http.htmlJava AJP  Connector: /docs/config/ajp.htmlAPR (HTTP/AJP) Connector: /docs/apr.htmlDefine a non-SSL/TLS HTTP/1.1 Connector on port 8080-->
<!--acceptCount="1000"
--><Connector port="8080" protocol="HTTP/1.1"connectionTimeout="20000"redirectPort="8443" maxThreads="30000"acceptCount="10000"/><!-- A "Connector" using the shared thread pool--><!--<Connector executor="tomcatThreadPool"port="8080" protocol="HTTP/1.1"connectionTimeout="20000"redirectPort="8443" />--><!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443This connector uses the NIO implementation. The defaultSSLImplementation will depend on the presence of the APR/nativelibrary and the useOpenSSL attribute of theAprLifecycleListener.Either JSSE or OpenSSL style configuration may be used regardless ofthe SSLImplementation selected. JSSE style configuration is used below.--><!--<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"maxThreads="150" SSLEnabled="true"><SSLHostConfig><Certificate certificateKeystoreFile="conf/localhost-rsa.jks"type="RSA" /></SSLHostConfig></Connector>--><!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2This connector uses the APR/native implementation which always usesOpenSSL for TLS.Either JSSE or OpenSSL style configuration may be used. OpenSSL styleconfiguration is used below.--><!--<Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol"maxThreads="150" SSLEnabled="true" ><UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" /><SSLHostConfig><Certificate certificateKeyFile="conf/localhost-rsa-key.pem"certificateFile="conf/localhost-rsa-cert.pem"certificateChainFile="conf/localhost-rsa-chain.pem"type="RSA" /></SSLHostConfig></Connector>--><!-- Define an AJP 1.3 Connector on port 8009 --><Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /><!-- An Engine represents the entry point (within Catalina) that processesevery request.  The Engine implementation for Tomcat stand aloneanalyzes the HTTP headers included with the request, and passes themon to the appropriate Host (virtual host).Documentation at /docs/config/engine.html --><!-- You should set jvmRoute to support load-balancing via AJP ie :<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">--><Engine name="Catalina" defaultHost="localhost"><!--For clustering, please take a look at documentation at:/docs/cluster-howto.html  (simple how to)/docs/config/cluster.html (reference documentation) --><!--<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>--><!-- Use the LockOutRealm to prevent attempts to guess user passwordsvia a brute-force attack --><Realm className="org.apache.catalina.realm.LockOutRealm"><!-- This Realm uses the UserDatabase configured in the global JNDIresources under the key "UserDatabase".  Any editsthat are performed against this UserDatabase are immediatelyavailable for use by the Realm.  --><Realm className="org.apache.catalina.realm.UserDatabaseRealm"resourceName="UserDatabase"/></Realm><Host name="localhost"  appBase="webapps"unpackWARs="true" autoDeploy="true"><!-- SingleSignOn valve, share authentication between web applicationsDocumentation at: /docs/config/valve.html --><!--<Valve className="org.apache.catalina.authenticator.SingleSignOn" />--><!-- Access log processes all example.Documentation at: /docs/config/valve.htmlNote: The pattern used is equivalent to using pattern="common" --><Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"prefix="localhost_access_log" suffix=".txt"pattern="%h %l %u %t &quot;%r&quot; %s %b" /></Host></Engine></Service>
</Server>

四.mysql数据库

“Can not connect to MySQL server. Too many connections”-mysql 1040错误,

这是因为访问MySQL且还未释放的连接数目已经达到MySQL的上限。通常,mysql的最大连接数默认是100, 最大可以达到16384

1.方式一(临时)

show variables like 'max_connections';(查可以看当前的最大连接数)set global max_connections=1000;(设置最大连接数为1000,可以再次查看是否设置成功)

这个是临时的重启mysql又变回来了,

1.方式二(修改配置永久生效)

MySQL配置文件my.ini 或 my.cnf的参数max_connections,将其改为max_connections=1000,然后重启MySQL即可。

技术支持:高岳峰,闫宇峰,施凯雷,杨珂

他的个人博客地址:http://120.78.93.197/

这是我的公众号 有最新的it咨询,和个人工作的记录:

这是我的个人微信遇到问题欢迎,提问:

最后加上高质量的淘宝店:如有质量问题随时滴滴我,童叟无欺!

【童装园服定制店铺】https://m.tb.cn/h.ef2J8CD?sm=6e0f74 点击链接,再选择浏览器咑閞;或復·制这段描述¥zfwjY4JVngW¥后到淘♂寳♀

高并发Nginx,Tomcat8,mysql数据库配置相关推荐

  1. 「高并发秒杀」mysql数据库引擎区别

    一.秒杀系统架构设计都有哪些关键点? 二.设计秒杀系统时应该注意的5个架构原则 架构原则:"4要1不要" 1.1.数据要尽里少 1.2. 请求数要尽里少 1.3.路径要尽里短 1. ...

  2. 读数据库遇到空就进行不下去_如何解决高并发场景下缓存+数据库双写不一致问题?...

    推荐阅读: 一只Tom猫:手撕分布式技术:限流.通讯.缓存,全部一锅端走送给你!​zhuanlan.zhihu.com 一只Tom猫:MySQL复习:20道常见面试题(含答案)+21条MySQL性能调 ...

  3. oracle单表高并发,见过这么高并发( logons current)的数据库么?

    见过这么高并发( logons current)的数据库么? SQL> select * from v$version; BANNER ----------------------------- ...

  4. 高并发 Nginx+Lua OpenResty系列教程汇总篇

    高并发 Nginx+Lua OpenResty系列教程汇总篇 <高并发 Nginx+Lua OpenResty系列(1)--环境搭建> <高并发 Nginx+Lua OpenRest ...

  5. MySQL数据库配置及高级操作

    MySQL数据库配置及高级操作 1 环境配置 1.1 MySQL安装与卸载 1.2 SQLyog安装 1.3 SQL简介 2 基本操作 2.1 DDL*(Data Definition Languag ...

  6. Liferay Portal使用MySQL数据库配置

    http://www.xy21.info/2012/03/31/%E4%B8%8Eliferay%E7%9A%84%E7%AC%AC%E4%B8%80%E6%AC%A1%E4%BA%B2%E5%AF% ...

  7. liferay mysql_Liferay Portal使用MySQL数据库配置

    在网上看了一些网友写的Liferay Portal使用MySQL数据库配置,还要手动弄导入脚本那些,很麻烦.倒不如来试试我下面的方法. Liferay Portal默认使用的是HSQLDB嵌入数据库, ...

  8. mysql数据库配置环境变量

    mysql数据库配置环境变量 这是我最初学习时记录下来的笔记,有些简陋! 1.下载最新版mysql软件,将mysql安装到系统目录中,记录当前安装目录: 如安装mysql到C:/program fil ...

  9. 高并发场景下更新数据库报错,记录一次 MySQL 死锁问题的解决

    作者 l 会点代码的大叔(CodeDaShu) 今天隔壁项目组的开发小姐姐找到我,说她们项目正在做压力测试,更新 MySQL 数据库的一张表时,总是发生死锁,日志大概是这个样子的: org.sprin ...

最新文章

  1. date new 转换时区_Pandas 时间序列 时区控制
  2. 最优控制理论 一、变分法和泛函极值问题
  3. .net 访问mysql链接池_c# – .NET SqlConnection类,连接池和重新连接逻辑
  4. Python Day11
  5. 1724: [Usaco2006 Nov]Fence Repair 切割木板( 贪心 )
  6. rk3188开机失败(ump_file_open() 251)
  7. 删除目录及目录下所有文件与子目录
  8. Java包的命名规则
  9. c# Winform应用程序开发规范
  10. Python工作笔记004---python字符串前面加上'r'的作用_u_b的含义
  11. 工作中常用知识点、工具总结
  12. (8)VTK 鼠标左右键控制模型旋转
  13. kiban可视化入门
  14. 计算机钢琴键盘,Everyone Piano
  15. 中国心率监测器行业市场供需与战略研究报告
  16. 漏洞挖掘——实验9 SQL Injection Attack Lab
  17. DSPE-PEG7-NHS ester分子式:C63H1117N2O20P琥珀酰亚胺PEG连接剂
  18. 教你怎么从Java8升级到Java11
  19. com.ctc.wstx.exc.WstxUnexpectedCharException:Unexpected错误解决
  20. 如何找回mysql密码

热门文章

  1. 漫话:全球 IPv4 地址正式耗尽?是时候说说到底什么是IPv4和IPv6了!
  2. MPB:南京​湖泊所王建军组-​群落构建过程的定量指标——扩散-生态位连续体指数...
  3. MPB:河湖着生硅藻样品采集、永久玻片制作及鉴定
  4. SCI论文投稿全程模板
  5. FM-2018-大熊猫的肠道菌群可能并没有特化出发酵纤维素的能力
  6. Error in x$e : $ operator is invalid for atomic vectors
  7. R语言dplyr包使用recode函数进行数据列内容编码、转换实战:类似于pandas中的map函数(例如,将内容从字符串映射到数值)
  8. 流放之路材质过滤怎么设置_三种不同材质的精密过滤设备特点
  9. 纳米孔(Oxford Nanopore)测序仪的学习笔记
  10. 抓图软件_Faststone capture8.3