废弃的Apache进程,还能持续多久?

发布于 2024-08-10 09:47:53 字数 1631 浏览 3 评论 0原文

假设有一个服务器进程花费的时间太长。客户抱怨说它“超时”。

如果我错了,请纠正我,但这个特定的超时可能与 apache 的超时设置有关,但不一定。我相信情况确实如此,因为在测试有问题的页面时,我们无法让它可靠地超时——大多数情况下,浏览器只会旋转多久。

如果与客户端的连接出现问题,超时设置将生效,如 文档。但如果连接正常,则由客户端关闭连接(我相信)。

我认为这也意味着如果客户端关闭浏览器,Apache 将达到超时限制(在我的例子中为 300 秒),并终止该进程。事实似乎并非如此。

以下是我的测试方法:
我在服务器上的一些代码中添加了一个 while 循环:

too_long = 2000
tstart = time.time()
f = open('/tmp/timeout_test.txt', 'w')
while True:
    time.sleep(100)
    elapsed = time.time() - tstart
    f.write('Loop, %s elapsed\n' % elapsed)
    if elapsed > too_long:
        break

然后打开网页来启动该循环,并在服务器上运行 netstat:(

~$ netstat -np | grep ESTAB | grep apache
tcp        0      0 10.102.123.6:443        10.102.119.101:53519    ESTABLISHED 16534/apache2
tcp        0      0 127.0.0.1:60299         127.0.0.1:5432          ESTABLISHED 16534/apache2

我在 10.102.119.101,服务器在 10.102.123.6)
然后我关闭浏览器并重新运行该 netstat 行:

~% netstat -np | grep ESTAB | grep apache
tcp        0      0 127.0.0.1:60299         127.0.0.1:5432          ESTABLISHED 16534/apache2

我的连接消失了,但服务器仍在循环中,我可以通过运行来确认:

~% lsof | grep timeout
apache2   16534   www-data   14w      REG        8,1        0     536533 /tmp/timeout_test.txt 

意味着 apache 进程仍然打开该文件。在接下来的 2000 秒里,当我跑步时:

~% cat /tmp/timeout_test.txt

我什么也没得到。 2000 秒后,netcat 行根本没有产生任何结果,tmp 文件被 while 循环的输出填充。

那么看来 Apache 进程只是按照要求执行操作,而不管客户端连接如何?那个环回连接是关于什么的?

So lets say there's a server process that takes way too long. The client complains that it "times out."

Correct me if I'm wrong, but this particular timeout could have to do with apache's timeout setting, but not necessarily. I believe this to be the case because when testing the page in question we couldn't get it to time out reliably - mostly the browser would just spin for as long as it took.

The timeout setting would come into effect if there were issues with the connection to the client, as described in the documentation. But if the connection was fine, it would be up to the client to close the connection (I believe).

I assumed this also meant that if the client closed their browser, Apache would hit the timeout limit (in my case, 300 seconds), and kill the process. This doesn't seem to be the case.

Here's how I tested it:
I added a while loop to some code on the server:

too_long = 2000
tstart = time.time()
f = open('/tmp/timeout_test.txt', 'w')
while True:
    time.sleep(100)
    elapsed = time.time() - tstart
    f.write('Loop, %s elapsed\n' % elapsed)
    if elapsed > too_long:
        break

I then open the web page to launch that loop, and ran netstat on the server:

~$ netstat -np | grep ESTAB | grep apache
tcp        0      0 10.102.123.6:443        10.102.119.101:53519    ESTABLISHED 16534/apache2
tcp        0      0 127.0.0.1:60299         127.0.0.1:5432          ESTABLISHED 16534/apache2

(that's me at 10.102.119.101, the server is at 10.102.123.6)
I then closed my browser and reran that netstat line:

~% netstat -np | grep ESTAB | grep apache
tcp        0      0 127.0.0.1:60299         127.0.0.1:5432          ESTABLISHED 16534/apache2

My connection disappeared, but the server was still in the loop, I could confirm by running:

~% lsof | grep timeout
apache2   16534   www-data   14w      REG        8,1        0     536533 /tmp/timeout_test.txt 

meaning the apache process still had that file open. For the next 2000 seconds, when I ran:

~% cat /tmp/timeout_test.txt

I got nothing. After 2000 seconds the netcat line produced nothing at all, and the tmp file was filled out with the output from the while loop.

So it seems that Apache process just does what it was asked to do, regardless of the client connection? And what is that loopback connection about?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烈酒灼喉 2024-08-17 09:47:53

正确的。在 C apache 模块中,您可以添加如下检查:

/* r is the 'request_rec' object from apache */
if (r->connection->aborted) {
    /* stop processing and return */
}

以验证客户端是否仍处于连接状态。也许 python 接口有类似的东西。

至于环回连接,它是一个与 postgresql 数据库的连接,只要该循环正在运行,就保持打开状态。

Correct. In a C apache module you can add a check like:

/* r is the 'request_rec' object from apache */
if (r->connection->aborted) {
    /* stop processing and return */
}

to verify that the client is still connected. Probably the python interface has something similar.

As for the loopback connection, it is a connection to a postgresql database kept open for as long as that loop is running.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文