Curl错误:Couldn't connect to server

在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 plain copy
  1. # prefork MPM  
  2. # StartServers: number of server processes to start  
  3. # MinSpareServers: minimum number of server processes which are kept spare  
  4. # MaxSpareServers: maximum number of server processes which are kept spare  
  5. # MaxClients: maximum number of server processes allowed to start  
  6. # MaxRequestsPerChild: maximum number of requests a server process serves  
  7. <IfModule mpm_prefork_module>  
  8.     StartServers          5  
  9.     MinSpareServers       5  
  10.     MaxSpareServers      10  
  11.     MaxClients          150  
  12.     MaxRequestsPerChild   0  
  13. </IfModule>  
  14.   
  15. # worker MPM  
  16. # StartServers: initial number of server processes to start  
  17. # MaxClients: maximum number of simultaneous client connections  
  18. # MinSpareThreads: minimum number of worker threads which are kept spare  
  19. # MaxSpareThreads: maximum number of worker threads which are kept spare  
  20. # ThreadsPerChild: constant number of worker threads in each server process  
  21. # MaxRequestsPerChild: maximum number of requests a server process serves  
  22. <IfModule mpm_worker_module>  
  23.     StartServers          2  
  24.     MaxClients          150  
  25.     MinSpareThreads      25  
  26.     MaxSpareThreads      75   
  27.     ThreadsPerChild      25  
  28.     MaxRequestsPerChild   0  
  29. </IfModule>  
  30.   
  31. # BeOS MPM  
  32. # StartThreads: how many threads do we initially spawn?  
  33. # MaxClients:   max number of threads we can have (1 thread == 1 client)  
  34. # MaxRequestsPerThread: maximum number of requests each thread will process  
  35. <IfModule mpm_beos_module>  
  36.     StartThreads            10  
  37.     MaxClients              50  
  38.     MaxRequestsPerThread 10000  
  39. </IfModule>  
  40.   
  41. # NetWare MPM  
  42. # ThreadStackSize: Stack size allocated for each worker thread  
  43. # StartThreads: Number of worker threads launched at server startup  
  44. # MinSpareThreads: Minimum number of idle threads, to handle request spikes  
  45. # MaxSpareThreads: Maximum number of idle threads  
  46. # MaxThreads: Maximum number of worker threads alive at the same time  
  47. # MaxRequestsPerChild: Maximum  number of requests a thread serves. It is   
  48. #                      recommended that the default value of 0 be set for this  
  49. #                      directive on NetWare.  This will allow the thread to   
  50. #                      continue to service requests indefinitely.                            
  51. <IfModule mpm_netware_module>  
  52.     ThreadStackSize      65536  
  53.     StartThreads           250  
  54.     MinSpareThreads         25  
  55.     MaxSpareThreads        250  
  56.     MaxThreads            1000  
  57.     MaxRequestsPerChild      0  
  58.     MaxMemFree             100  
  59. </IfModule>  
  60.   
  61. # OS/2 MPM  
  62. # StartServers: Number of server processes to maintain  
  63. # MinSpareThreads: Minimum number of idle threads per process,   
  64. #                  to handle request spikes  
  65. # MaxSpareThreads: Maximum number of idle threads per process  
  66. # MaxRequestsPerChild: Maximum number of connections per server process  
  67. <IfModule mpm_mpmt_os2_module>  
  68.     StartServers           2  
  69.     MinSpareThreads        5  
  70.     MaxSpareThreads       10  
  71.     MaxRequestsPerChild    0  
  72. </IfModule>  
  73.   
  74. # WinNT MPM  
  75. # ThreadsPerChild: constant number of worker threads in the server process  
  76. # MaxRequestsPerChild: maximum  number of requests a server process serves  
  77. <IfModule mpm_winnt_module>  
  78.     ThreadsPerChild      450  
  79.     MaxRequestsPerChild    0  
  80. </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 plain copy
  1. <IfModule mpm_worker_module>  
  2.     StartServers          2  
  3.     MaxClients          150 #最大连接数  
  4.     MinSpareThreads      25  
  5.     MaxSpareThreads      75   
  6.     ThreadsPerChild      25 #每个子进程的服务线程数目  
  7.     MaxRequestsPerChild   0 #单个子进程在其生命周期内处理的总请求数限制,当某个子进程处理过的总请求数到达这个限制后这个进程就会被回收,如果设为0,那么这个进程永远不会过期  
  8. </IfModule>  

修改MaxClients值,重启apache服务,问题解决!
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值