When large number of files are added to download queue at once, the download speed gets significantly slower on a platform we are working for. We found that the most part of time are consumed for sigaction system call in curl.
The number of times of sigaction call becomes enormously as we increase file handles registered by curl_multi_add_handle(). Here is the test results that show the total count of sigaction calls with different number of file handles. Each file size is 64KB.
* 512 files (32MB in total): 348144 times (of sigaction call)
* 1024 files (64MB in total): 1344192 times
* 2048 files (128MB in total): 5300697 times
* 4096 files (256MB in total): 21088311 times
It seems the times of sigaction-call grow along O(N^2) where N is the number of file handles.
The sigaction is there to ignore SIGPIPE signals that is triggered when the other end of socket are closed. However for the platform we are targeting, we have little concern about the unexpected signals since the socket are configured with SO_NOSIGPIPE option with setsockopt(), and use send() with MSG_NOSIGNAL as its forth argument.
Also curl with c-ares or threaded async DNS resolver doesn't rely on SIGALRM signal to detect timeouts.
The cost of syscall is relatively high because of user-kernel context switching. These sigaction can be avoided by a curl option, CURLOPT_NOSIGNAL (https://curl.se/libcurl/c/CURLOPT_NOSIGNAL.html). With the option enabled, curl omits to install signal handlers by assuming no signals triggered for the process.
Created attachment 431756 [details]
Why does curl block SIGPIPE even on platforms supporting MSG_NOSIGNAL and SO_NOSIGPIPE?
Increasing sigaction calls as O(N^2) seems like a curl bug.
Committed r279046 (238966@main): <https://commits.webkit.org/238966@main>
All reviewed patches have been landed. Closing bug and clearing flags on attachment 431756 [details].
Not all systems provide enough way to avoid SIGPIPE. SO_NOSIGPIPE socket option is available in BSD based OS. MSG_NOSIGNAL flag has been brought in since Linux 2.2.
Thank you for your review.