当前位置: 首页>>代码示例>>Python>>正文


Python server_pool.ServerPool类代码示例

本文整理汇总了Python中server_pool.ServerPool的典型用法代码示例。如果您正苦于以下问题:Python ServerPool类的具体用法?Python ServerPool怎么用?Python ServerPool使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ServerPool类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: new_server

	def new_server(self, port, passwd, cfg):
		protocol = cfg.get('protocol', ServerPool.get_instance().config.get('protocol', 'origin'))
		method = cfg.get('method', ServerPool.get_instance().config.get('method', 'None'))
		obfs = cfg.get('obfs', ServerPool.get_instance().config.get('obfs', 'plain'))
		logging.info('db start server at port [%s] pass [%s] protocol [%s] method [%s] obfs [%s]' % (port, passwd, protocol, method, obfs))
		ServerPool.get_instance().new_server(port, cfg)
		self.force_update_transfer.add(port)
开发者ID:xcracker,项目名称:autoss,代码行数:7,代码来源:db_transfer.py

示例2: thread_db

	def thread_db(obj):
		import socket
		import time
		global db_instance
		timeout = 60
		socket.setdefaulttimeout(timeout)
		last_rows = []
		db_instance = obj()
		ServerPool.get_instance()
		shell.log_shadowsocks_version()
		import resource
		logging.info('current process RLIMIT_NOFILE resource: soft %d hard %d'  % resource.getrlimit(resource.RLIMIT_NOFILE))
		try:
			while True:
				load_config()
				db_instance.load_cfg()
				try:
					db_instance.push_db_all_user()
					rows = db_instance.pull_db_all_user()
					if rows:
						db_instance.pull_ok = True
					db_instance.del_server_out_of_bound_safe(last_rows, rows)
					last_rows = rows
				except Exception as e:
					trace = traceback.format_exc()
					logging.error(trace)
					#logging.warn('db thread except:%s' % e)
				if db_instance.event.wait(get_config().UPDATE_TIME) or not ServerPool.get_instance().thread.is_alive():
					break
		except KeyboardInterrupt as e:
			pass
		db_instance.del_servers()
		ServerPool.get_instance().stop()
		db_instance = None
开发者ID:luffySaw,项目名称:shadowsocks-R,代码行数:34,代码来源:db_transfer.py

示例3: del_server_out_of_bound_safe

 def del_server_out_of_bound_safe(rows):
     # 停止超流量的服务
     # 启动没超流量的服务
     for row in rows:
         if ServerPool.get_instance().server_is_run(row[0]):
             if row[1] + row[2] >= row[3]:
                 logging.info("db stop server at port [%s]" % (row[0]))
                 ServerPool.get_instance().del_server(row[0])
         else:
             if row[5] == 1 and row[6] == 1 and row[1] + row[2] < row[3]:
                 logging.info("db start server at port [%s] pass [%s]" % (row[0], row[4]))
                 ServerPool.get_instance().new_server(row[0], row[4])
开发者ID:ayongw,项目名称:shadowsocks-csharp-server,代码行数:12,代码来源:db_transfer.py

示例4: del_servers

	def del_servers():
		for port in [v for v in ServerPool.get_instance().tcp_servers_pool.keys()]:
			if ServerPool.get_instance().server_is_run(port) > 0:
				ServerPool.get_instance().cb_del_server(port)
		for port in [v for v in ServerPool.get_instance().tcp_ipv6_servers_pool.keys()]:
			if ServerPool.get_instance().server_is_run(port) > 0:
				ServerPool.get_instance().cb_del_server(port)
开发者ID:luffySaw,项目名称:shadowsocks-R,代码行数:7,代码来源:db_transfer.py

示例5: thread_db

	def thread_db(obj):
		import socket
		import time
		global db_instance
		timeout = 60
		socket.setdefaulttimeout(timeout)
		last_rows = []
		db_instance = obj()
		ServerPool.get_instance()
		shell.log_shadowsocks_version()

		try:
			import resource
			logging.info('current process RLIMIT_NOFILE resource: soft %d hard %d'  % resource.getrlimit(resource.RLIMIT_NOFILE))
		except:
			pass

		try:
			while True:
				load_config()
				db_instance.load_cfg()
				try:
					db_instance.push_db_all_user()
					rows = db_instance.pull_db_all_user()
					if rows:
						db_instance.pull_ok = True
						config = shell.get_config(False)
						for port in config['additional_ports']:
							val = config['additional_ports'][port]
							val['port'] = int(port)
							val['enable'] = 1
							val['transfer_enable'] = 1024 ** 7
							val['u'] = 0
							val['d'] = 0
							if "password" in val:
								val["passwd"] = val["password"]
							rows.append(val)
					db_instance.del_server_out_of_bound_safe(last_rows, rows)
					last_rows = rows
				except Exception as e:
					trace = traceback.format_exc()
					logging.error(trace)
					#logging.warn('db thread except:%s' % e)
				if db_instance.event.wait(get_config().UPDATE_TIME) or not ServerPool.get_instance().thread.is_alive():
					break
		except KeyboardInterrupt as e:
			pass
		db_instance.del_servers()
		ServerPool.get_instance().stop()
		db_instance = None
开发者ID:chasenn,项目名称:Shadowsowcks1Click,代码行数:50,代码来源:db_transfer.py

示例6: push_db_all_user

    def push_db_all_user(self):
        #更新用户流量到数据库
        last_transfer = self.last_get_transfer
        curr_transfer = ServerPool.get_instance().get_servers_transfer()
        #上次和本次的增量
        dt_transfer = {}
        for id in curr_transfer.keys():
            if id in last_transfer:
                if last_transfer[id][0] == curr_transfer[id][0] and last_transfer[id][1] == curr_transfer[id][1]:
                    continue
                elif curr_transfer[id][0] == 0 and curr_transfer[id][1] == 0:
                    continue
                elif last_transfer[id][0] <= curr_transfer[id][0] and \
                last_transfer[id][1] <= curr_transfer[id][1]:
                    dt_transfer[id] = [curr_transfer[id][0] - last_transfer[id][0],
                                       curr_transfer[id][1] - last_transfer[id][1]]
                else:
                    dt_transfer[id] = [curr_transfer[id][0], curr_transfer[id][1]]
            else:
                if curr_transfer[id][0] == 0 and curr_transfer[id][1] == 0:
                    continue
                dt_transfer[id] = [curr_transfer[id][0], curr_transfer[id][1]]

        self.last_get_transfer = curr_transfer

        for id in dt_transfer.keys():
            ins = SSInstance.objects.get(port=id)
            # print u
            ins.u += dt_transfer[id][0]
            ins.d += dt_transfer[id][1]
            # print u
            ins.save()
开发者ID:josephwuzw,项目名称:shadowsocks,代码行数:32,代码来源:db_transfer.py

示例7: push_db_all_user

    def push_db_all_user(self):
        #更新用户流量到数据库
        last_transfer = self.last_get_transfer
        curr_transfer = ServerPool.get_instance().get_servers_transfer()
        #上次和本次的增量
        dt_transfer = {}
        for id in curr_transfer.keys():
            if id in last_transfer:
                if last_transfer[id][0] == curr_transfer[id][0] and last_transfer[id][1] == curr_transfer[id][1]:
                    continue
                elif curr_transfer[id][0] == 0 and curr_transfer[id][1] == 0:
                    continue
                elif last_transfer[id][0] <= curr_transfer[id][0] and \
                last_transfer[id][1] <= curr_transfer[id][1]:
                    dt_transfer[id] = [curr_transfer[id][0] - last_transfer[id][0],
                                       curr_transfer[id][1] - last_transfer[id][1]]
                else:
                    dt_transfer[id] = [curr_transfer[id][0], curr_transfer[id][1]]
            else:
                if curr_transfer[id][0] == 0 and curr_transfer[id][1] == 0:
                    continue
                dt_transfer[id] = [curr_transfer[id][0], curr_transfer[id][1]]

        self.last_get_transfer = curr_transfer
        query_head = 'UPDATE users'
        query_sub_when = ''
        query_sub_when2 = ''
        query_sub_when3 = ''
        query_sub_in = None
        last_time = time.time()
        for id in dt_transfer.keys():
            totalU = dt_transfer[id][0]
            totalD = dt_transfer[id][1]
            query_sub_when += ' WHEN %s THEN u+%s' % (id, totalU)
            query_sub_when2 += ' WHEN %s THEN d+%s' % (id, totalD)
            query_sub_when3 += ' WHEN %s THEN total_transfer+%s' % (id, totalD+totalU)
            if query_sub_in is not None:
                query_sub_in += ',%s' % id
            else:
                query_sub_in = '%s' % id
        if query_sub_when == '':
            return
        query_sql = query_head + ' SET u = CASE port' + query_sub_when + \
                    ' END, d = CASE port' + query_sub_when2 + \
                    ' END, total_transfer = CASE port' + query_sub_when3 + \
                    ' END, t = ' + str(int(last_time)) + \
                    ' WHERE port IN (%s)' % query_sub_in
        #print query_sql
        conn = cymysql.connect(host=Config.MYSQL_HOST, port=Config.MYSQL_PORT, user=Config.MYSQL_USER,
                               passwd=Config.MYSQL_PASS, db=Config.MYSQL_DB, charset='utf8')
        cur = conn.cursor()
        cur.execute(query_sql)
        cur.close()
        conn.commit()
        conn.close()
开发者ID:spoonwep,项目名称:shadowsocks,代码行数:55,代码来源:db_transfer.py

示例8: push_db_all_user

	def push_db_all_user(self):
		#更新用户流量到数据库
		last_transfer = self.last_get_transfer
		curr_transfer = ServerPool.get_instance().get_servers_transfer()
		#上次和本次的增量
		dt_transfer = {}
		for id in curr_transfer.keys():
			if id in last_transfer:
				if last_transfer[id][0] == curr_transfer[id][0] and last_transfer[id][1] == curr_transfer[id][1]:
					continue
				elif curr_transfer[id][0] == 0 and curr_transfer[id][1] == 0:
					continue
				elif last_transfer[id][0] <= curr_transfer[id][0] and \
				last_transfer[id][1] <= curr_transfer[id][1]:
					dt_transfer[id] = [int((curr_transfer[id][0] - last_transfer[id][0]) * Config.TRANSFER_MUL),
										int((curr_transfer[id][1] - last_transfer[id][1]) * Config.TRANSFER_MUL)]
				else:
					dt_transfer[id] = [int(curr_transfer[id][0] * Config.TRANSFER_MUL),
										int(curr_transfer[id][1] * Config.TRANSFER_MUL)]
			else:
				if curr_transfer[id][0] == 0 and curr_transfer[id][1] == 0:
					continue
				dt_transfer[id] = [int(curr_transfer[id][0] * Config.TRANSFER_MUL),
									int(curr_transfer[id][1] * Config.TRANSFER_MUL)]

		query_head = 'UPDATE member'
		query_sub_when = ''
		query_sub_when2 = ''
		query_sub_in = None
		last_time = time.time()
		for id in dt_transfer.keys():
			if dt_transfer[id][0] == 0 and dt_transfer[id][1] == 0:
				continue
			query_sub_when += ' WHEN %s THEN flow_up+%s' % (id, dt_transfer[id][0])
			query_sub_when2 += ' WHEN %s THEN flow_down+%s' % (id, dt_transfer[id][1])
			if query_sub_in is not None:
				query_sub_in += ',%s' % id
			else:
				query_sub_in = '%s' % id
		if query_sub_when == '':
			return
		query_sql = query_head + ' SET flow_up = CASE port' + query_sub_when + \
					' END, flow_down = CASE port' + query_sub_when2 + \
					' END, lastConnTime = ' + str(int(last_time)) + \
					' WHERE port IN (%s)' % query_sub_in
		#print query_sql
		conn = cymysql.connect(host=Config.MYSQL_HOST, port=Config.MYSQL_PORT, user=Config.MYSQL_USER,
								passwd=Config.MYSQL_PASS, db=Config.MYSQL_DB, charset='utf8')
		cur = conn.cursor()
		cur.execute(query_sql)
		cur.close()
		conn.commit()
		conn.close()
		self.last_get_transfer = curr_transfer
开发者ID:ss-share,项目名称:ss-share.github.io,代码行数:54,代码来源:db_transfer.py

示例9: del_server_out_of_bound_safe

 def del_server_out_of_bound_safe(rows):
 #停止超流量的服务
 #启动没超流量的服务
 #修改下面的逻辑要小心包含跨线程访问
     for row in rows:
         if ServerPool.get_instance().server_is_run(row[0]) is True:
             if row[5] == 0 or row[6] == 0:
                 #stop disable or switch off user
                 logging.info('db stop server at port [%s] reason: disable' % (row[0]))
                 ServerPool.get_instance().del_server(row[0])
             elif row[1] + row[2] >= row[3]:
                 #stop out bandwidth user
                 logging.info('db stop server at port [%s] reason: out bandwidth' % (row[0]))
                 ServerPool.get_instance().del_server(row[0])
             if ServerPool.get_instance().tcp_servers_pool[row[0]]._config['password'] != row[4]:
                 #password changed
                 logging.info('db stop server at port [%s] reason: password changed' % (row[0]))
                 ServerPool.get_instance().del_server(row[0]) 
         else:
             if row[5] == 1 and row[6] == 1 and row[1] + row[2] < row[3]:
                 logging.info('db start server at port [%s] pass [%s]' % (row[0], row[4]))
                 ServerPool.get_instance().new_server(row[0], row[4])
开发者ID:osdebianly,项目名称:laravel-many-user-shadowsocks,代码行数:22,代码来源:db_transfer.py

示例10: thread_db

	def thread_db():
		import socket
		import time
		timeout = 60
		socket.setdefaulttimeout(timeout)
		last_rows = []
		try:
			while True:
				reload(Config)
				try:
					DbTransfer.get_instance().push_db_all_user()
					rows = DbTransfer.get_instance().pull_db_all_user()
					DbTransfer.del_server_out_of_bound_safe(last_rows, rows)
					last_rows = rows
				except Exception as e:
					trace = traceback.format_exc()
					logging.error(trace)
					#logging.warn('db thread except:%s' % e)
				if DbTransfer.get_instance().event.wait(Config.MYSQL_UPDATE_TIME) or not ServerPool.get_instance().thread.is_alive():
					break
		except KeyboardInterrupt as e:
			pass
		DbTransfer.del_servers()
		ServerPool.get_instance().stop()
开发者ID:ss-share,项目名称:ss-share.github.io,代码行数:24,代码来源:db_transfer.py

示例11: push_db_all_user

	def push_db_all_user(self):
		if self.pull_ok is False:
			return
		#更新用户流量到数据库
		last_transfer = self.last_update_transfer
		curr_transfer = ServerPool.get_instance().get_servers_transfer()
		#上次和本次的增量
		dt_transfer = {}
		for id in self.force_update_transfer: #此表中的用户统计上次未计入的流量
			if id in self.last_get_transfer and id in last_transfer:
				dt_transfer[id] = [self.last_get_transfer[id][0] - last_transfer[id][0], self.last_get_transfer[id][1] - last_transfer[id][1]]

		for id in curr_transfer.keys():
			if id in self.force_update_transfer:
				continue
			#算出与上次记录的流量差值,保存于dt_transfer表
			if id in last_transfer:
				if curr_transfer[id][0] + curr_transfer[id][1] - last_transfer[id][0] - last_transfer[id][1] <= 0:
					continue
				dt_transfer[id] = [curr_transfer[id][0] - last_transfer[id][0],
								curr_transfer[id][1] - last_transfer[id][1]]
			else:
				if curr_transfer[id][0] + curr_transfer[id][1] <= 0:
					continue
				dt_transfer[id] = [curr_transfer[id][0], curr_transfer[id][1]]

			#有流量的,先记录在线状态
			if id in self.last_get_transfer:
				if curr_transfer[id][0] + curr_transfer[id][1] > self.last_get_transfer[id][0] + self.last_get_transfer[id][1]:
					self.onlineuser_cache[id] = curr_transfer[id][0] + curr_transfer[id][1]
			else:
				self.onlineuser_cache[id] = curr_transfer[id][0] + curr_transfer[id][1]

		self.onlineuser_cache.sweep()

		update_transfer = self.update_all_user(dt_transfer) #返回有更新的表
		for id in update_transfer.keys(): #其增量加在此表
			if id not in self.force_update_transfer: #但排除在force_update_transfer内的
				last = self.last_update_transfer.get(id, [0,0])
				self.last_update_transfer[id] = [last[0] + update_transfer[id][0], last[1] + update_transfer[id][1]]
		self.last_get_transfer = curr_transfer
		for id in self.force_update_transfer:
			if id in self.last_update_transfer:
				del self.last_update_transfer[id]
			if id in self.last_get_transfer:
				del self.last_get_transfer[id]
		self.force_update_transfer = set()
开发者ID:luffySaw,项目名称:shadowsocks-R,代码行数:47,代码来源:db_transfer.py

示例12: render_GET

 def render_GET(self, request):
     retcode = 1
     retmsg = 'unknow err'
     if request.uri.startswith('/cmd/del_server'):
         while True:
             try:
                 if not 'key' in request.args or Config.REST_APIKEY != request.args['key'][0]:
                     retmsg = 'key error'
                     break
                 port = int(request.args['port'][0])
                 if ServerPool.get_instance().del_server(port) is True:
                     retcode = 0
                     retmsg = 'success'
             except Exception, e:
                 retmsg = str(e)
             finally:
                 break
开发者ID:ayongw,项目名称:shadowsocks-csharp-server,代码行数:17,代码来源:restful_cmd.py

示例13: del_server_out_of_bound_safe

 def del_server_out_of_bound_safe(rows):
 #停止超流量的服务
 #启动没超流量的服务
     for row in rows:
         if ServerPool.get_instance().server_is_run(row['port']) > 0:
             if row['u'] + row['d'] >= row['transfer_enable'] or (not row['enable']):
                 logging.info('db stop server at port [%s]' % (row['port']))
                 ServerPool.get_instance().del_server(row['port'])
         elif ServerPool.get_instance().server_run_status(row['port']) is False:
             if row['switch'] and row['enable'] and  row['u'] + row['d'] < row['transfer_enable']:
                 logging.info('db start server at port [%s] pass [%s]' % (row['port'], row['passwd']))
                 ServerPool.get_instance().new_server(row['port'], row['passwd'])
开发者ID:josephwuzw,项目名称:shadowsocks,代码行数:12,代码来源:db_transfer.py

示例14: del_server_out_of_bound_safe

    def del_server_out_of_bound_safe(rows):
    #停止超流量的服务
    #启动没超流量的服务
        for row in rows:
            if ServerPool.get_instance().server_is_run(row[0]) > 0:
		if ((row[1] + row[2] >= row[3]) or (row[5] == 0)):
                    logging.info('db stop server at port [%s]' % (row[0]))
                    ServerPool.get_instance().del_server(row[0])
            elif ServerPool.get_instance().server_run_status(row[0]) is False:
                if row[5] == 1 and  row[1] + row[2] < row[3]:
                    logging.info('db start server at port [%s] pass [%s]' % (row[0], row[4]))
                    ServerPool.get_instance().new_server(row[0], row[4])
开发者ID:alphabity,项目名称:shadowsocks,代码行数:12,代码来源:db_transfer.py

示例15: del_server_out_of_bound_safe

    def del_server_out_of_bound_safe(rows):
    #停止超流量的服务
    #启动没超流量的服务
        for row in rows:
            if ServerPool.get_instance().server_is_run(row[0]) > 0:

                if datetime.datetime.now() >= row[7]:
                #if row[1] + row[2] >= row[3] and lasttime >= row[7]:
                    logging.info('db stop server at port [%s]' % (row[0]))
                    ServerPool.get_instance().del_server(row[0])
            elif ServerPool.get_instance().server_run_status(row[0]) is False:
                if row[5] == 1 and row[6] == 1 and  datetime.datetime.now() < row[7]:
                    logging.info('db start server at port [%s] pass [%s]' % (row[0], row[4]))
                    ServerPool.get_instance().new_server(row[0], row[4])
开发者ID:rexchou,项目名称:shadowsocks-manyuser,代码行数:14,代码来源:db_transfer.py


注:本文中的server_pool.ServerPool类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。