Skip to content

Commit fc9aae3

Browse files
committed
改善gevent环境下获取google server name时,select函数导致cpu高的问题
1 parent 6ee969f commit fc9aae3

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

checkip.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
if g_usegevent == 1:
3939
try:
4040
from gevent import monkey
41-
monkey.patch_all(select=False)
41+
monkey.patch_all(Event=True)
4242
g_useOpenSSL = 0
4343
from gevent import sleep
4444
except ImportError:
@@ -359,7 +359,7 @@ def getssldomain(self, threadname, ip):
359359
if domain is None and len(gwsname) > 0:
360360
domain="defaultgws"
361361
if domain is not None:
362-
PRINT("ip: %s,CN: %s,svr: %s" % (ip, domain,gwsname))
362+
PRINT("ip: %s,CN: %s,svr: %s,ok:%d" % (ip, domain,gwsname,checkvalidssldomain(domain,gwsname)))
363363
return domain, costtime,timeout,gwsname
364364
else:
365365
s.settimeout(g_conntimeout)
@@ -393,7 +393,7 @@ def getssldomain(self, threadname, ip):
393393
if domain is None and len(gwsname) > 0:
394394
domain="defaultgws"
395395
if domain is not None:
396-
PRINT("ip: %s,CN: %s,svr: %s" % (ip, domain,gwsname))
396+
PRINT("ip: %s,CN: %s,svr: %s,ok:%d" % (ip, domain,gwsname,checkvalidssldomain(domain,gwsname)))
397397
return domain, costtime,timeout,gwsname
398398
except SSLError as e:
399399
time_end = time.time()
@@ -439,10 +439,20 @@ def getgooglesvrname(self,conn,sock,ip):
439439
conn.write(myreq)
440440
data=""
441441
sock.setblocking(0)
442+
selectcnt = 0
442443
while True:
443-
infds, outfds, errfds = select.select([sock, ], [], [], g_conntimeout)
444-
if len(infds) == 0:
445-
break
444+
if g_usegevent == 0:
445+
infds, outfds, errfds = select.select([sock, ], [], [], g_conntimeout)
446+
if len(infds) == 0:
447+
return ""
448+
else:
449+
infds, outfds, errfds = select.select([sock, ], [], [], 0)
450+
if len(infds) == 0:
451+
selectcnt += 1
452+
if selectcnt >= 8:
453+
return ""
454+
sleep(0.5)
455+
continue
446456
trycnt = 0
447457
while True:
448458
try:

0 commit comments

Comments
 (0)