Curl错误:Couldn't connect to server
2015-11-12 17:19
225 查看
在Linux系统下,开了200个线程分别curl同一个网站,结果程序爆错了,一堆。
出错信息:Couldn't connect to server
打开curl选项调试:
curl_easy_setopt(m_pCurl, CURLOPT_VERBOSE, 1);
也定位不了错误,后来发现200个线程,每次都有264个任务可以正常处理,而且程序的线程池会自动调度,空闲线程处理新任务,所以才会有264这个数字。
我访问的网站是在Windows创建的一个网站后台,经过询问,得知Windows的web服务器使用的是apache。
此时错误问题可以初步诊断为:apache的最大连接数导致的问题。
于是经过一番修改(修改方法还是国外的,google伟大):
原文:
It seems that the httpd-mpm.conf file holds the answer. But I'm not sure what settings should be changed or even what module apache is running as.
httpd-mpm.conf:
[plain] view
plaincopy
# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 150
MaxRequestsPerChild 0
</IfModule>
# worker MPM
# StartServers: initial number of server processes to start
# MaxClients: maximum number of simultaneous client connections
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadsPerChild: constant number of worker threads in each server process
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_worker_module>
StartServers 2
MaxClients 150
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0
</IfModule>
# BeOS MPM
# StartThreads: how many threads do we initially spawn?
# MaxClients: max number of threads we can have (1 thread == 1 client)
# MaxRequestsPerThread: maximum number of requests each thread will process
<IfModule mpm_beos_module>
StartThreads 10
MaxClients 50
MaxRequestsPerThread 10000
</IfModule>
# NetWare MPM
# ThreadStackSize: Stack size allocated for each worker thread
# StartThreads: Number of worker threads launched at server startup
# MinSpareThreads: Minimum number of idle threads, to handle request spikes
# MaxSpareThreads: Maximum number of idle threads
# MaxThreads: Maximum number of worker threads alive at the same time
# MaxRequestsPerChild: Maximum number of requests a thread serves. It is
# recommended that the default value of 0 be set for this
# directive on NetWare. This will allow the thread to
# continue to service requests indefinitely.
<IfModule mpm_netware_module>
ThreadStackSize 65536
StartThreads 250
MinSpareThreads 25
MaxSpareThreads 250
MaxThreads 1000
MaxRequestsPerChild 0
MaxMemFree 100
</IfModule>
# OS/2 MPM
# StartServers: Number of server processes to maintain
# MinSpareThreads: Minimum number of idle threads per process,
# to handle request spikes
# MaxSpareThreads: Maximum number of idle threads per process
# MaxRequestsPerChild: Maximum number of connections per server process
<IfModule mpm_mpmt_os2_module>
StartServers 2
MinSpareThreads 5
MaxSpareThreads 10
MaxRequestsPerChild 0
</IfModule>
# WinNT MPM
# ThreadsPerChild: constant number of worker threads in the server process
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_winnt_module>
ThreadsPerChild 450
MaxRequestsPerChild 0
</IfModule>
Answers:
The solution is to uncomment the MPM config include in httpd.conf
在httpd.conf文件中,打开该行注释,否则修改无效:
# Server-pool management (MPM specific)
Include conf/extra/httpd-mpm.conf
apache有2种模式:prefork和worker
通过执行:httpd.exe -l,结果里面没有prefork.c文件,说明本机的apache使用的是worker模式,于是就修改:
[plain] view
plaincopy
<IfModule mpm_worker_module>
StartServers 2
MaxClients 150 #最大连接数
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25 #每个子进程的服务线程数目
MaxRequestsPerChild 0 #单个子进程在其生命周期内处理的总请求数限制,当某个子进程处理过的总请求数到达这个限制后这个进程就会被回收,如果设为0,那么这个进程永远不会过期
</IfModule>
修改MaxClients值,重启apache服务,问题解决!
出错信息:Couldn't connect to server
打开curl选项调试:
curl_easy_setopt(m_pCurl, CURLOPT_VERBOSE, 1);
也定位不了错误,后来发现200个线程,每次都有264个任务可以正常处理,而且程序的线程池会自动调度,空闲线程处理新任务,所以才会有264这个数字。
我访问的网站是在Windows创建的一个网站后台,经过询问,得知Windows的web服务器使用的是apache。
此时错误问题可以初步诊断为:apache的最大连接数导致的问题。
于是经过一番修改(修改方法还是国外的,google伟大):
原文:
It seems that the httpd-mpm.conf file holds the answer. But I'm not sure what settings should be changed or even what module apache is running as.
httpd-mpm.conf:
[plain] view
plaincopy
# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 150
MaxRequestsPerChild 0
</IfModule>
# worker MPM
# StartServers: initial number of server processes to start
# MaxClients: maximum number of simultaneous client connections
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadsPerChild: constant number of worker threads in each server process
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_worker_module>
StartServers 2
MaxClients 150
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0
</IfModule>
# BeOS MPM
# StartThreads: how many threads do we initially spawn?
# MaxClients: max number of threads we can have (1 thread == 1 client)
# MaxRequestsPerThread: maximum number of requests each thread will process
<IfModule mpm_beos_module>
StartThreads 10
MaxClients 50
MaxRequestsPerThread 10000
</IfModule>
# NetWare MPM
# ThreadStackSize: Stack size allocated for each worker thread
# StartThreads: Number of worker threads launched at server startup
# MinSpareThreads: Minimum number of idle threads, to handle request spikes
# MaxSpareThreads: Maximum number of idle threads
# MaxThreads: Maximum number of worker threads alive at the same time
# MaxRequestsPerChild: Maximum number of requests a thread serves. It is
# recommended that the default value of 0 be set for this
# directive on NetWare. This will allow the thread to
# continue to service requests indefinitely.
<IfModule mpm_netware_module>
ThreadStackSize 65536
StartThreads 250
MinSpareThreads 25
MaxSpareThreads 250
MaxThreads 1000
MaxRequestsPerChild 0
MaxMemFree 100
</IfModule>
# OS/2 MPM
# StartServers: Number of server processes to maintain
# MinSpareThreads: Minimum number of idle threads per process,
# to handle request spikes
# MaxSpareThreads: Maximum number of idle threads per process
# MaxRequestsPerChild: Maximum number of connections per server process
<IfModule mpm_mpmt_os2_module>
StartServers 2
MinSpareThreads 5
MaxSpareThreads 10
MaxRequestsPerChild 0
</IfModule>
# WinNT MPM
# ThreadsPerChild: constant number of worker threads in the server process
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_winnt_module>
ThreadsPerChild 450
MaxRequestsPerChild 0
</IfModule>
Answers:
The solution is to uncomment the MPM config include in httpd.conf
在httpd.conf文件中,打开该行注释,否则修改无效:
# Server-pool management (MPM specific)
Include conf/extra/httpd-mpm.conf
apache有2种模式:prefork和worker
通过执行:httpd.exe -l,结果里面没有prefork.c文件,说明本机的apache使用的是worker模式,于是就修改:
[plain] view
plaincopy
<IfModule mpm_worker_module>
StartServers 2
MaxClients 150 #最大连接数
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25 #每个子进程的服务线程数目
MaxRequestsPerChild 0 #单个子进程在其生命周期内处理的总请求数限制,当某个子进程处理过的总请求数到达这个限制后这个进程就会被回收,如果设为0,那么这个进程永远不会过期
</IfModule>
修改MaxClients值,重启apache服务,问题解决!
相关文章推荐
- Mybatis缓存和Redis缓存服务器的案例分析
- HDU 3934 (旋转卡壳)
- html5与html4区别
- CentOS7挂载分区教程
- ajax实现文件下载
- jQuery学习之prop和attr的区别
- WIN7 64位 没有ACCESS驱动的问题
- Leetcode Valid Anagram
- 基于cydia Hook在线热修复补丁方案
- Mysql自动化安装
- ffmpeg重要结构体之AVCodec
- android ProgressBar和SeekBar简单应用
- FriendlyARM Tiny210开发板硬件基础 第二篇--汇编调用c语言
- 【es6】let和const
- 2015年10月31日 学习计划
- python库:fuzzywuzzy
- Android 5.0 权限管理, apk安装失败
- css3 @media 用法
- STM32低功耗模式--STOP模式
- Activity启动模式