from treq import get
from twisted.internet import reactor
# This method is called whenever a response is recieved
def done(response):
if response.code == 200:
# do something with response
reactor.stop()
for i in range(100000):
get("http://www.somesite.com").addCallback(done)
reactor.run()
我同意@anekix,使用twisted是最好的方法。在
你需要知道一件事,无论你使用哪种方法来请求10000个HTTP请求,都有一个开放文件描述符限制,在Linux中基本上设置为1000个。 这意味着只能有1000个并发TCP连接。但是,您可以通过Linux中的配置
/etc/security/limits.conf
来增加这个值你可以/应该用twisted。
treq
基于twisted的很简单,因为它的完全异步请求数/秒将非常高,比如1000甚至更多。在使用twisted进行异步编程的学习曲线很高,但最终会得到非常好的结果。如需进一步参考,请查看http://treq.readthedocs.io/en/latest/api.html
为什么不使用Scapy包来生成sendp(第2层)的流量,它的性能非常好。它也很容易生成不同的包
相关问题 更多 >
编程相关推荐