我有以下 shell 脚本。问题是我想并行/并发运行事务,而不是等待一个请求完成以转到下一个请求。例如,如果我发出 20 个请求,我希望它们同时执行。
for ((request=1;request<=20;request++))
do
for ((x=1;x<=20;x++))
do
time curl -X POST --header "http://localhost:5000/example"
done
done
有指导吗?
最佳答案
您可以使用带有 -P
选项的 xargs
并行运行任何命令:
seq 1 200 | xargs -n1 -P10 curl "http://localhost:5000/example"
这将运行 curl
命令 200 次,最多并行执行 10 个作业。
关于bash - 并行运行多个 curl 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46362284/