连接重用与Curl,Apache和mod_wsgi

时间:2022-10-25 21:36:29

I am deploying a mod_wsgi application on top of Apache, and have a client program that uses Curl.

我正在Apache上部署mod_wsgi应用程序,并有一个使用Curl的客户端程序。

On the CURL api on the user side, I have it attempt to reuse connection, but looking at the connections from wireshark, I see that for every HTTP request/response, a new connection is made.

在用户端的CURL api上,我尝试重用连接,但是查看来自wireshark的连接,我看到每个HTTP请求/响应都会建立一个新的连接。

At the end of every HTTP request, the HTTP response header has "Connection: Close"

在每个HTTP请求结束时,HTTP响应头具有“连接:关闭”

Is this the same as Keep-Alive? What do I need to do on the Apache/Mod_wsgi side to enable connection re-use?

这和Keep-Alive一样吗?我需要在Apache / Mod_wsgi端做什么才能重新连接?

1 个解决方案

#1


You would not generally need to do anything to Apache as support for keep alive connections would normally be on by default. Look at the KeepAlive directive in Apache configuration to work out what it is set to.

您通常不需要对Apache执行任何操作,因为默认情况下通常会启用保持连接的支持。查看Apache配置中的KeepAlive指令以确定其设置的内容。

On top of that, for keep alive connections to work the WSGI application must be setting a content length in the response, or returning a list for the response where the list contains only a single string. In this latter case mod_wsgi will automatically add a content length for the response. The response would generally also need to be a successful response as most error responses would cause connection to be closed regardless.

最重要的是,为了使活动连接起作用,WSGI应用程序必须在响应中设置内容长度,或者返回列表仅包含单个字符串的响应列表。在后一种情况下,mod_wsgi将自动为响应添加内容长度。响应通常也需要成功响应,因为大多数错误响应都会导致连接被关闭。

Even having done all that, the issue is whether the ability of curl to fetch multiple URLs even makes use of keep alive connections. Obviously separate invocations of curl will not be able to, so that you are even asking this questions suggests you are trying to use that feature of curl. Only other option would be if you were using a custom client linked to libcurl and using its library and so you meant libcurl.

即使完成了所有这些,问题在于curl获取多个URL的能力是否仍然使用保持连接。显然单独调用卷曲是不可能的,因此您甚至会问这个问题表明您正在尝试使用卷曲的这一特性。如果您使用链接到libcurl的自定义客户端并使用其库,那么只有其他选项,因此您的意思是libcurl。

Do note that if access to Apache is via a proxy, the proxy may not implement keep alive and so stop the whole mechanism from working.

请注意,如果通过代理访问Apache,代理可能无法实现保持活动,因此停止整个机制的工作。

To give more information, need to know about how you are using curl.

要提供更多信息,需要了解您如何使用curl。

#1


You would not generally need to do anything to Apache as support for keep alive connections would normally be on by default. Look at the KeepAlive directive in Apache configuration to work out what it is set to.

您通常不需要对Apache执行任何操作,因为默认情况下通常会启用保持连接的支持。查看Apache配置中的KeepAlive指令以确定其设置的内容。

On top of that, for keep alive connections to work the WSGI application must be setting a content length in the response, or returning a list for the response where the list contains only a single string. In this latter case mod_wsgi will automatically add a content length for the response. The response would generally also need to be a successful response as most error responses would cause connection to be closed regardless.

最重要的是,为了使活动连接起作用,WSGI应用程序必须在响应中设置内容长度,或者返回列表仅包含单个字符串的响应列表。在后一种情况下,mod_wsgi将自动为响应添加内容长度。响应通常也需要成功响应,因为大多数错误响应都会导致连接被关闭。

Even having done all that, the issue is whether the ability of curl to fetch multiple URLs even makes use of keep alive connections. Obviously separate invocations of curl will not be able to, so that you are even asking this questions suggests you are trying to use that feature of curl. Only other option would be if you were using a custom client linked to libcurl and using its library and so you meant libcurl.

即使完成了所有这些,问题在于curl获取多个URL的能力是否仍然使用保持连接。显然单独调用卷曲是不可能的,因此您甚至会问这个问题表明您正在尝试使用卷曲的这一特性。如果您使用链接到libcurl的自定义客户端并使用其库,那么只有其他选项,因此您的意思是libcurl。

Do note that if access to Apache is via a proxy, the proxy may not implement keep alive and so stop the whole mechanism from working.

请注意,如果通过代理访问Apache,代理可能无法实现保持活动,因此停止整个机制的工作。

To give more information, need to know about how you are using curl.

要提供更多信息,需要了解您如何使用curl。