baichongyang hace 3 años
padre
commit
93a9058304
Se han modificado 4 ficheros con 30 adiciones y 26 borrados
  1. 24 24
      aiocache.py
  2. 1 1
      asgi.py
  3. 1 1
      config.py
  4. 4 0
      utils.py

+ 24 - 24
aiocache.py

@@ -11,35 +11,35 @@ redis_info = config_.REDIS_INFO
 # R = get_redis_connect()
 # R = get_redis_connect()
 
 
 pg_info = config_.HOLOGRES_INFO
 pg_info = config_.HOLOGRES_INFO
-# P = aiopg.connect(database=pg_info['dbname'],
-#                                user=pg_info['user'],
-#                                password=pg_info['password'],
-#                                host=pg_info['host'])
+P = aiopg.connect(database=pg_info['dbname'],
+                               user=pg_info['user'],
+                               password=pg_info['password'],
+                               host=pg_info['host'],
+                                 port=pg_info['port'])
 
 
 
 
 R = aioredis.from_url(redis_info['host'], password=redis_info['password'])
 R = aioredis.from_url(redis_info['host'], password=redis_info['password'])
 # async def get_redis_connect():
 # async def get_redis_connect():
 #     return await aioredis.from_url(redis_info['host'], password=redis_info['password'])
 #     return await aioredis.from_url(redis_info['host'], password=redis_info['password'])
 
 
-# async def pg_getdata(sql):
-#     P = await aiopg.connect(database=pg_info['dbname'],
-#                                user=pg_info['user'],
-#                                password=pg_info['password'],
-#                                host=pg_info['host'],
-#                                port=pg_info['port'])
-#     cur = await P.cursor()
-#     await cur.execute(sql)
-#     ret = await cur.fetchall()
-#     return ret
-
-dsn = f'dbname={pg_info["dbname"]} user={pg_info["user"]} password={pg_info["password"]} host={pg_info["host"]} port={pg_info["port"]}'
-print(dsn)
 async def pg_getdata(sql):
 async def pg_getdata(sql):
-    pool = await aiopg.create_pool(dsn)
-    async with pool.acquire() as conn:
-        async with conn.cursor() as cur:
-            await cur.execute(sql)    
-            return await cur.fetchall()
+    P = await aiopg.connect(database=pg_info['dbname'],
+                               user=pg_info['user'],
+                               password=pg_info['password'],
+                               host=pg_info['host'],
+                               port=pg_info['port'])
+    cur = await P.cursor()
+    await cur.execute(sql)
+    ret = await cur.fetchall()
+    return ret
+
+# dsn = f'dbname={pg_info["dbname"]} user={pg_info["user"]} password={pg_info["password"]} host={pg_info["host"]} port={pg_info["port"]}'
+# async def pg_getdata(sql):
+#     pool = await aiopg.create_pool(dsn)
+#     async with pool.acquire() as conn:
+#         async with conn.cursor() as cur:
+#             await cur.execute(sql)    
+#             return await cur.fetchall()
 
 
 async def key_exists(key_name):
 async def key_exists(key_name):
     """
     """
@@ -173,9 +173,9 @@ async def add_data_with_set(key_name, values, expire_time=30*60):
     :param expire_time: 过期时间,单位:s,默认0.5小时
     :param expire_time: 过期时间,单位:s,默认0.5小时
     :return: None
     :return: None
     """
     """
-    R.sadd(key_name, *values)
+    await R.sadd(key_name, *values)
     # 设置过期时间
     # 设置过期时间
-    R.expire(key_name, expire_time)
+    await R.expire(key_name, expire_time)
 
 
 async def data_exists_with_set(key_name, value):
 async def data_exists_with_set(key_name, value):
     """
     """

+ 1 - 1
asgi.py

@@ -3,4 +3,4 @@ from route import create_app
 app = create_app()
 app = create_app()
 
 
 
 
-#uvicorn asgi:app
+#uvicorn asgi:app  --workers=4

+ 1 - 1
config.py

@@ -51,7 +51,7 @@ class DevelopmentConfig(BaseConfig):
 
 
     # Hologres连接参数,本地使用
     # Hologres连接参数,本地使用
     HOLOGRES_INFO = {
     HOLOGRES_INFO = {
-        'host': 'hgprecn-cn-7pp28y18c00c-cn-hangzhou.hologres.aliyuncs.com',
+        'host': 'hgprecn-cn-7pp28y18c00c-cn-hangzhou-vpc.hologres.aliyuncs.com',
         'port': 80,
         'port': 80,
         'dbname': 'dssm',
         'dbname': 'dssm',
         'user': 'LTAI5tMPqPy9yboQAf1mBCCN',
         'user': 'LTAI5tMPqPy9yboQAf1mBCCN',

+ 4 - 0
utils.py

@@ -25,6 +25,7 @@ async def request_post(url, data, timeout=1):
             async with session.post(url, data=data) as res:
             async with session.post(url, data=data) as res:
                 if res.status == 200:
                 if res.status == 200:
                     res_data = json.loads(await res.text())
                     res_data = json.loads(await res.text())
+                    print('res_data', res_data)
                     return res_data
                     return res_data
                 else:
                 else:
                     return None
                     return None
@@ -144,6 +145,7 @@ class FilterVideos(object):
         :param video_ids: 视频id列表 type-list
         :param video_ids: 视频id列表 type-list
         :return: filtered_videos
         :return: filtered_videos
         """
         """
+        b_time = time.time()
         if len(video_ids) == 1:
         if len(video_ids) == 1:
             sql = "set hg_experimental_enable_shard_pruning=off; " \
             sql = "set hg_experimental_enable_shard_pruning=off; " \
                   "SELECT video_id " \
                   "SELECT video_id " \
@@ -169,6 +171,8 @@ class FilterVideos(object):
 
 
         data = await aiocache.pg_getdata(sql=sql)
         data = await aiocache.pg_getdata(sql=sql)
         filtered_videos = [temp[0] for temp in data]
         filtered_videos = [temp[0] for temp in data]
+        e_time = time.time()
+        print('holo time',e_time-b_time)
         return filtered_videos
         return filtered_videos
 
 
     async def filter_video_viewed(self, video_ids, types=(1,)):
     async def filter_video_viewed(self, video_ids, types=(1,)):