Curl error: couldn't connect to server

Source: Internet
Author: User

In Linux, 200 threads are opened for the same website with curl, and the program burst into an error.
Error message: couldn't connect to server
Enable curl option debugging:
Curl_easy_setopt (m_pcurl, curlopt_verbose, 1 );
The error cannot be located. Later, we found that 200 threads can process 264 tasks at a time, and the thread pool of the program will be automatically scheduled to process new tasks in Idle threads, so there will be the number 264.

The website I visited is in the background of a website created in windows. After inquiry, I learned that the Web server of Windows uses Apache.

At this time, the error can be preliminarily diagnosed as the problem caused by the maximum number of connections of Apache.

So after some modifications (the modification method is still foreign, and Google is great ):
Original article:
It seems that the httpd-mpm.conf file holds the answer. But I'm not sure what settings shocould be changed or even what module Apache is running.

Httpd-mpm.conf:

# 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

In the httpd. conf file, open the line comment; otherwise, the modification is invalid:
# Server-pool management (MPM specific)
Include CONF/extra/httpd-mpm.conf

Apache has two modes: prefork and worker.
Run httpd.exe-L. The result does not contain the prefork. c file, which indicates that Apache on the local machine uses the worker mode, so modify:

<Ifmodule mpm_worker_module> startservers 2 maxclients 150 # maximum number of connections minsparethreads 25 maxsparethreads 75 threadsperchild 25 # Number of service threads of each sub-process maxrequestsperchild 0 # Total number of requests processed by a single sub-process number Limit, when the total number of requests processed by a sub-process reaches this limit, the process will be recycled. If it is set to 0, the process will never expire. </ifmodule>

Modify the maxclients value, restart the apache service, and solve the problem!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.