尽快发送 HTTP 请求
为了测试我的程序,我想尽可能快地发送大约 50 个 http 请求。 目前我正在使用 bash 脚本,它调用curl & 发送每个请求
curl "http://my.host.com/test.php?param=1" &
curl "http://my.host.com/test.php?param=2" &
curl "http://my.host.com/test.php?param=100" &
,但似乎不够快。 我想因为每次curl调用都会先建立一个tcp连接,如果只建立一次连接,性能可以得到提高。 有没有其他工具可以有效地发送请求?
In order to test my program, I want to send about 50 http requests as fast as possile. Currently I'm using bash script which calls curl & to send each request like
curl "http://my.host.com/test.php?param=1" &
curl "http://my.host.com/test.php?param=2" &
curl "http://my.host.com/test.php?param=100" &
but it seems not fast enough. I guess since each curl call will establish a tcp connection first, and performance can be improved if the connection is established only once. Is there any other tools to send request effciently?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
尽管您后台下载了所有下载,但它仍无法执行的原因是操作系统仍然必须加载curl(但仍然从缓存中),为它创建一个进程,解析参数等。
您需要可以的东西并行发送 N 个请求而不启动新进程。
The reason why this doesn't perform despite the fact that you background all the downloads is that the OS still has to load curl (from cache but still), create a process for it, parse the parameters, etc.
You need something that can send N requests in parallel without starting new processes.
JMeter 是负载测试 apache。
从他们的网站:
JMeter is a good way to load test apache.
From their site:
Apache 附带了一个名为“ab”的程序用于基准测试。 在网络上,有许多网站压力测试应用程序可供您使用。
Apache comes with a program called "ab" for benchmarking. On the net, there are many stress test applications for websites that you can use.
在 PHP 中(当然也在 CURL 中)有一些非常好的东西< /a>.
在 google.com 上执行 1000 次常规 GET 大约需要 16 秒,大约每秒 63 个请求。
In PHP (and also in CURL of course) there is something really nice.
It takes about 16 seconds to do 1000 regular GETs on google.com, about 63 requests per second.
Apache JMeter 在多台机器上同时运行可能会相当快。
Apache JMeter in more than one machine running at the same could be pretty fast.
不要使用bash。 使用任何其他脚本语言(Perl、Python 等),然后创建单个连接并尽快处理请求。 为了获得奖励积分,请启动多个线程,以便测试程序处理同时连接的能力!
Don't use bash. Use any other scripting language (Perl, Python, whatever), then create a single connection and pound away on the requests as quickly as possible. For bonus points, launch multiple threads so that you test your program's ability to handle simultaneous connections!