def web_ip_cache(self):
while True:
t1 = time.time()
try:
r = redis.StrictRedis(REDIS_SERVER,REDIS_PORT,DB_FOR_IP)
num,ips = self.db_set_select(r,REDIS_SET_CACHE,False,WEB_CACHE_IP_NUM)
self.cur_num = num
self.cur_pos = 0
self.len = num
#print ips
#print "cur num",self.cur_num,self.cur_pos,self.len
if num >0 and ips != None and len(ips) > 0 :
glist = [gevent.spawn(self.test_ip,r,ips,True) for i in range(GEVENT_NUM)]
gevent.joinall(glist)
times = 0
while self.cur_num < WEB_CACHE_IP_NUM and times < 1024:
#print "cur num",self.cur_num
n = (WEB_CACHE_IP_NUM - self.cur_num)*2
num,ips = self.db_set_select(r,REDIS_SORT_SET_COUNTS,True,n)
self.cur_pos = 0
self.len = num
times += 1
if num == 0 or ips == None:
continue
glist = [gevent.spawn(self.test_ip,r,ips,False) for i in range(GEVENT_NUM)]
gevent.joinall(glist)
#print "cur num end ",self.cur_num
except Exception as e:
#print e
log.error("PID:%d web cache error:%s" % (os.getpid(),e))
finally:
t2 = time.time()
#print "sleep"
t = WEB_CACHE_REFRESH - ( t2 - t1 )
if t > 0:
time.sleep(t)
评论列表
文章目录