Apache服务器如何在epoll事件结构上排队请求?

huangapple go评论67阅读模式
英文:

How does apache server queue the request on epoll events structure?

问题

我正在尝试实现我的自己的Apache服务器,我正在使用epoll编写套接字服务器,events数组需要一个确定数量的元素,但如果我不知道应用程序会有多少请求,我该如何定义这个数量呢?

struct epoll_event events[应该是多大的尺寸?];

我还没有尝试过任何方法。我已经搜索了一些信息,但似乎Apache并不使用epoll,它有自己的实现(或者这是我理解的)。

英文:

I'm trying to implement my own apache server, and I was coding the socket server with epoll, and the events array needs a determinated numbers of elements, but how should I define that number if I don't know the total amount of request that the application would have.

struct epoll_event events[What would be the size?];

I don't have tried anything yet. I've searched some info but apache does not seem to use epoll, it has its own implementation (or that is what I've understood).

答案1

得分: 0

你以完全相同的方式确定这一点,就像确定读取未知长度文件的缓冲区大小一样:你使用固定大小的缓冲区,然后读取,然后继续读取,直到达到文件的末尾。

同样的原理在这里也适用。你要确定你的事件缓冲区的大小,然后开始重复地读取事件。

没有适用于每个使用 epoll_wait 的应用程序的通用公式。这是你首先需要进行合理猜测,然后仔细监视实际结果,并根据需要微调事件缓冲区大小的事情。

epoll_wait 会根据其参数的设置,阻塞直到至少有一个事件可读。然后无论如何(请原谅双关语),继续读取指定数量的事件。

如果还有更多的事件可用,剩余的事件将保持未读状态,然后将由下一次对 epoll_wait 的调用读取。

英文:

You determine this in exact same fashion you determine the size of the buffer for reading a file of unknown length: you use a fixed-size buffer, then read, and then continue reading until reaching the end of the file.

The same exact principle applies here. You figure out the size of your event buffer, then start reading events, repeatedly.

There is no universal formula that works for every application that uses epoll_wait. This is something that you will first have to make an educated guess, and then carefully monitor the actual results, and perhaps fine-tune the size of your event buffer, if needed.

epoll_wait will, depending on its parameters, block until there's at least one event to read. Then in any event (pardon the pun) proceed and read up to the number of events that was specified.

If there are more events available, the remaining events remain unread and then will be read by the next call to epoll_wait.

huangapple
  • 本文由 发表于 2023年5月7日 05:55:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76191335.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定