ck 连接池

This commit is contained in:
wuaho 2021-07-27 16:08:49 +08:00
parent 773e1fac82
commit adf440f977
2 changed files with 6 additions and 5 deletions

View File

@ -5,13 +5,13 @@ import pandas as pd
class CKDrive: class CKDrive:
ClientPool = dict() ClientPool = set()
@classmethod @classmethod
async def _execute(cls, *args, **kwargs): async def _execute(cls, *args, **kwargs):
key, client = cls.ClientPool.popitem() client = cls.ClientPool.pop()
res = await client.execute(*args, **kwargs) res = await client.execute(*args, **kwargs)
CKDrive.ClientPool[key] = client CKDrive.ClientPool.add(client)
return res return res
async def execute(self, sql) -> dict: async def execute(self, sql) -> dict:

View File

@ -7,8 +7,9 @@ from .ckdb import CKDrive
async def connect_to_ck(pool_size=100): async def connect_to_ck(pool_size=100):
for i in range(pool_size): for i in range(pool_size):
client = Client(**settings.CK_CONFIG) client = Client(**settings.CK_CONFIG)
CKDrive.ClientPool[i] = client CKDrive.ClientPool.add(client)
async def close_ck_connection(): async def close_ck_connection():
await CKDrive.client.disconnect() for c in CKDrive.ClientPool:
await c.disconnect()