|
@@ -4,22 +4,14 @@ import threading
|
|
|
|
|
|
from django.http import JsonResponse
|
|
from django.http import JsonResponse
|
|
from django.views.generic.base import View
|
|
from django.views.generic.base import View
|
|
-from AnsjerPush.config import CONFIG_EUR, CONFIG_INFO, CONFIG_CN, CONFIG_US
|
|
|
|
|
|
|
|
|
|
+from AnsjerPush.config import CONFIG_EUR, CONFIG_INFO, CONFIG_US, CONFIG_CN
|
|
|
|
+from Object.GlobalThreadPoolObject import GlobalThreadPool
|
|
from Object.RedisObject import RedisObject
|
|
from Object.RedisObject import RedisObject
|
|
from Service.DevicePushService import DevicePushService
|
|
from Service.DevicePushService import DevicePushService
|
|
-from concurrent.futures import ThreadPoolExecutor
|
|
|
|
|
|
|
|
TIME_LOGGER = logging.getLogger('time')
|
|
TIME_LOGGER = logging.getLogger('time')
|
|
-# 创建一个全局的线程池实例
|
|
|
|
-# 线程池最大数量
|
|
|
|
-# 1、CPU密集型:操作内存处理的业务,一般线程数设置为:CPU核数 + 1 或者 CPU核数*2。核数为4的话一般设置5或8
|
|
|
|
-# 2、IO密集型:文件操作,网络操作,数据库操作,一般线程设置为:CPU核数 / (1-0.9),核数为4的话,一般设置 40
|
|
|
|
-executor = ThreadPoolExecutor(max_workers=20)
|
|
|
|
-if CONFIG_INFO == CONFIG_US or CONFIG_INFO == CONFIG_EUR:
|
|
|
|
- ThreadPoolExecutor(max_workers=80)
|
|
|
|
-elif CONFIG_INFO == CONFIG_CN:
|
|
|
|
- ThreadPoolExecutor(max_workers=40)
|
|
|
|
|
|
+ERROR_INFO_LOGGER = logging.getLogger('error_info')
|
|
|
|
|
|
|
|
|
|
# 移动侦测V2接口
|
|
# 移动侦测V2接口
|
|
@@ -141,7 +133,8 @@ class NotificationV2View(View):
|
|
'uid_set_push_list': uid_set_push_list}
|
|
'uid_set_push_list': uid_set_push_list}
|
|
|
|
|
|
# 使用全局的线程池提交推送任务
|
|
# 使用全局的线程池提交推送任务
|
|
- executor.submit(push_and_save_data, **params)
|
|
|
|
|
|
+ thread_pool = GlobalThreadPool()
|
|
|
|
+ thread_pool.submit(push_and_save_data, **params)
|
|
|
|
|
|
# 异步推送消息和保存数据
|
|
# 异步推送消息和保存数据
|
|
# push_thread = threading.Thread(
|
|
# push_thread = threading.Thread(
|
|
@@ -170,8 +163,8 @@ class NotificationV2View(View):
|
|
uid, n_time, event_type, json.dumps(res_data)))
|
|
uid, n_time, event_type, json.dumps(res_data)))
|
|
return JsonResponse(status=200, data=res_data)
|
|
return JsonResponse(status=200, data=res_data)
|
|
except Exception as e:
|
|
except Exception as e:
|
|
- TIME_LOGGER.info('V2推送接口异常uid:{},etk:{},error_line:{},error_msg:{}'.
|
|
|
|
- format(uid, etk, e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
|
|
+ ERROR_INFO_LOGGER.info('V2推送接口异常,uid:{},etk:{},error_line:{},error_msg:{}'.
|
|
|
|
+ format(uid, etk, e.__traceback__.tb_lineno, repr(e)))
|
|
data = {
|
|
data = {
|
|
'error_line': e.__traceback__.tb_lineno,
|
|
'error_line': e.__traceback__.tb_lineno,
|
|
'error_msg': repr(e)
|
|
'error_msg': repr(e)
|
|
@@ -182,11 +175,16 @@ class NotificationV2View(View):
|
|
def push_and_save_data(**params):
|
|
def push_and_save_data(**params):
|
|
uid = params['uid']
|
|
uid = params['uid']
|
|
TIME_LOGGER.info('{}开始异步存表和推送'.format(uid))
|
|
TIME_LOGGER.info('{}开始异步存表和推送'.format(uid))
|
|
|
|
+
|
|
|
|
+ # 线程池推送消息
|
|
|
|
+ thread_pool = GlobalThreadPool()
|
|
|
|
+ thread_pool.submit(DevicePushService.push_msg, **params)
|
|
|
|
+
|
|
# 异步推送消息
|
|
# 异步推送消息
|
|
- push_thread = threading.Thread(
|
|
|
|
- target=DevicePushService.push_msg,
|
|
|
|
- kwargs=params)
|
|
|
|
- push_thread.start()
|
|
|
|
|
|
+ # push_thread = threading.Thread(
|
|
|
|
+ # target=DevicePushService.push_msg,
|
|
|
|
+ # kwargs=params)
|
|
|
|
+ # push_thread.start()
|
|
# 保存推送数据
|
|
# 保存推送数据
|
|
result = DevicePushService.save_msg_push(**params)
|
|
result = DevicePushService.save_msg_push(**params)
|
|
TIME_LOGGER.info('{}存表结果:{}'.format(uid, result))
|
|
TIME_LOGGER.info('{}存表结果:{}'.format(uid, result))
|