Do not reuse cURL sockets

This patch sets CURLOPT_FORBID_REUSE, which tells cURL to close all
connections when they are done. By default, connections are held open
for later use unless explicitly closed or expired by a timeout. This can
improve performance if the same instance is used for multiple requests
to a single host.

We never have that: a host receives only one message per queue job, so
keeping the socket opened for 60 seconds (the default timeout) is
totally useless.

In addition, keeping the sockets open can cause problems for larger
instances with fast workers and a lot of jobs. Mainly, diaspora/#6485 is
caused by this very issue, which is resolved by this as well.
This commit is contained in:
Dennis Schubert 2016-07-01 23:40:58 +02:00
parent 699c74a8f0
commit 7c3f430bcf
No known key found for this signature in database
GPG key ID: 5A0304BEA7966D7E

View file

@ -11,12 +11,13 @@ module DiasporaFederation
# @return [Hash] hydra opts # @return [Hash] hydra opts
def self.hydra_opts def self.hydra_opts
@hydra_opts ||= { @hydra_opts ||= {
maxredirs: DiasporaFederation.http_redirect_limit, maxredirs: DiasporaFederation.http_redirect_limit,
timeout: DiasporaFederation.http_timeout, timeout: DiasporaFederation.http_timeout,
method: :post, method: :post,
verbose: DiasporaFederation.http_verbose, verbose: DiasporaFederation.http_verbose,
cainfo: DiasporaFederation.certificate_authorities, cainfo: DiasporaFederation.certificate_authorities,
headers: { forbid_reuse: true,
headers: {
"Expect" => "", "Expect" => "",
"Transfer-Encoding" => "", "Transfer-Encoding" => "",
"User-Agent" => DiasporaFederation.http_user_agent "User-Agent" => DiasporaFederation.http_user_agent