Apache/PHP 测试服务器按请求节流
我最近在我的计算机上设置了一个在虚拟机中运行的测试服务器,这样我就可以使用 XDebug 进行交互式调试等操作。在大多数情况下,它非常好用,但是当从同一个客户端同时向服务器运行多个请求时,我遇到了障碍。
问题是来宾-主机网络连接并不真正作为物理连接存在,因此它将以计算机硬件允许的速度运行。这通常不是一个大问题,但我正在尝试实现 APC 文件上传监控,这需要 AJAX 请求与文件上传并行运行以监控其性能。在现实世界中,网络会引入滞后和延迟等,从而为 AjAX 请求与文件上传并行运行留下足够的未使用带宽。然而,在测试机中,AJAX 请求在上传完成之前无法从服务器获取任何数据,因为绝对没有可用带宽。
是否可以在虚拟机(在 Apache、PHP 或某些 Linux 实用程序中)中设置某种带宽管理来限制每个 HTTP 请求的可用带宽?例如每个请求限制为1mbps,但是客户端和服务器之间可以同时存在多个请求?我希望,如果可以做到这一点,它将允许 AJAX 请求在上传过程中获取其数据,而不是在上传实际完成之前停滞不前。
我尝试了一个名为 IPRelay 的实用程序,但我似乎无法让它工作,或者至少不能以限制每个请求的方式工作。
I've recently set up a test server running in a virtual machine on my computer so I can do such things as interactive debugging with XDebug. For the most part it's pretty sweet, but I've run into a snag when running multiple requests to the server at once from the same client.
The problem is that guest-host network connection doesn't really exist as a physical connection, so it will run as fast as the computer hardware will allow. This isn't usually a big issue, but I'm trying to implement APC file upload monitoring, and this requires an AJAX request to run in parallel to the file upload to monitor its performance. In the real world, the network would introduce lag and latency and suchlike, leaving enough unused bandwidth for the AjAX request to run in parallel with the file upload. However, in the test machine, the AJAX request can't fetch any data from the server until the upload is finished as there's absolutely no bandwidth left available to it.
Is it possible to set up some kind of bandwidth management in the virtual machine (in Apache, PHP or some Linux utility) that could limit the bandwidth available per HTTP request? For example so that each request is limited to 1mbps, but several requests can exist between the client and the server at the same time? I'm hoping that if this can be done it will allow the AJAX request to fetch its data while the upload is progressing instead of being stalled until the upload actually completes.
I tried a utility called IPRelay, but I don't seem able to get it to work, or at least not in a way that limits per request.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您所要求的称为流量整形。
Lighttpd(Apache 的替代品)原生支持此
对于 Apache,有很少有方法可以做到这一点。
这是一个可能相关的 ServerFault 问题...
What you're asking for is called Traffic Shaping.
Lighttpd (an alternative to Apache) supports this natively
For Apache, there are a few ways of doing it.
Here's a ServerFault Question that may be relevant...
感谢您的回复。然而,我发现了一个名为 iprelay 的 Linux 方便小实用程序,它可以让我限制连接,它似乎让我打开多个连接,每个连接都限制到指定的限制。这就是我今天用来测试我的 APC 代码的方法,一切似乎都工作正常。
Thanks for the reply. However, I found a handy little utility for Linux called iprelay that lets me throttle connections, it seems to let me have multiple connections open with each connection throttled to the specified limit. That's what I've been using today for testing my APC code and it all seems to be working fine.