Gevent vs 扫描同步处理,为什么它们的速度大致相同?
Gevent vs sync processing for scanning, why are they approximately the same speed?
def cn(host, port):
try:
conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
conn.connect((host, port))
print '[+]%d/tcp open' % port
conn.close()
except:
pass
#print '[-]%d/tcp closed' % port
def ge():
st = time.time()
threads = [gevent.spawn(cn, '127.0.0.1', i) for i in xrange(1000)]
gevent.joinall(threads)
print "using gevent - " + str(time.time() - st)
def ss():
st = time.time()
for i in range(1, 1000):
connScan('127.0.0.1', i)
print "using sync processing - " + str(time.time() - st)
Gevent 只比同步处理快一点点。为什么?
是否可以改进上述代码以使用 gevent 使其更快?
大多数端口已关闭,因此完全没有阻塞可以从 gevent 版本获得加速。
def cn(host, port):
try:
conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
conn.connect((host, port))
print '[+]%d/tcp open' % port
conn.close()
except:
pass
#print '[-]%d/tcp closed' % port
def ge():
st = time.time()
threads = [gevent.spawn(cn, '127.0.0.1', i) for i in xrange(1000)]
gevent.joinall(threads)
print "using gevent - " + str(time.time() - st)
def ss():
st = time.time()
for i in range(1, 1000):
connScan('127.0.0.1', i)
print "using sync processing - " + str(time.time() - st)
Gevent 只比同步处理快一点点。为什么?
是否可以改进上述代码以使用 gevent 使其更快?
大多数端口已关闭,因此完全没有阻塞可以从 gevent 版本获得加速。