From 8d69943c5fc77d5c7a8699e7957ed2c06717644f Mon Sep 17 00:00:00 2001 From: Micheal X Date: Wed, 29 Mar 2023 15:08:24 +1300 Subject: [PATCH] release 5.1.1 fix issue and improve performance. --- README.md | 5 +++-- code/default/lib/noarch/front_base/config.py | 1 + code/default/lib/noarch/front_base/http_common.py | 8 +++++++- .../lib/noarch/front_base/http_dispatcher.py | 14 ++++++++++++-- code/default/smart_router/local/pipe_socks.py | 10 ++++++---- code/default/version.txt | 2 +- .../x_tunnel/local/cloudflare_front/config.py | 4 ++-- 7 files changed, 32 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 91d40674cc..4ed45e3fb3 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,9 @@ ### 最新公告: - 2023-03-28 -* 新版 5.1.0,内置ChatGPT + 2023-03-29 +* 新版 5.1.1, 提升速度、稳定性 +* 5.1.0,内置ChatGPT * 原来是4.x.x 的老版本,需要重新下载新版安装,不能应用内升级。 diff --git a/code/default/lib/noarch/front_base/config.py b/code/default/lib/noarch/front_base/config.py index 6af6f83462..cd03c269ac 100644 --- a/code/default/lib/noarch/front_base/config.py +++ b/code/default/lib/noarch/front_base/config.py @@ -20,6 +20,7 @@ def set_default(self): self.set_var("dispather_max_workers", 60) self.set_var("dispather_score_factor", 1) self.set_var("dispather_max_idle_workers", 30) + self.set_var("dispather_worker_max_continue_fail", 2) self.set_var("max_task_num", 100) diff --git a/code/default/lib/noarch/front_base/http_common.py b/code/default/lib/noarch/front_base/http_common.py index c72af2ddef..d5137e32dc 100644 --- a/code/default/lib/noarch/front_base/http_common.py +++ b/code/default/lib/noarch/front_base/http_common.py @@ -192,6 +192,7 @@ def __init__(self, logger, ip_manager, config, ssl_sock, close_cb, retry_task_cb self.accept_task = True self.keep_running = True self.processed_tasks = 0 + self.continue_fail_tasks = 0 self.speed_history = [] self.last_recv_time = self.ssl_sock.create_time self.last_send_time = self.ssl_sock.create_time @@ -249,7 +250,12 @@ def get_host(self, task_host): return self.ssl_sock.host def is_life_end(self): - if time.time() > self.life_end_time: + now = time.time() + if now > self.life_end_time: + return True + elif now - self.last_recv_time > 230: + return True + elif self.continue_fail_tasks > self.config.dispather_worker_max_continue_fail: return True else: return False diff --git a/code/default/lib/noarch/front_base/http_dispatcher.py b/code/default/lib/noarch/front_base/http_dispatcher.py index b0e903ced3..d7f2937b4c 100644 --- a/code/default/lib/noarch/front_base/http_dispatcher.py +++ b/code/default/lib/noarch/front_base/http_dispatcher.py @@ -170,13 +170,19 @@ def get_worker(self, nowait=False): while self.running: best_score = 99999999 best_worker = None + good_worker = 0 idle_num = 0 now = time.time() for worker in self.workers: - if not worker.accept_task or worker.is_life_end(): + if worker.is_life_end(): # self.logger.debug("not accept") continue + good_worker += 1 + + if not worker.accept_task: + continue + if worker.version == "1.1": idle_num += 1 else: @@ -189,7 +195,7 @@ def get_worker(self, nowait=False): best_score = score best_worker = worker - if len(self.workers) < self.config.dispather_max_workers and \ + if good_worker < self.config.dispather_max_workers and \ (best_worker is None or idle_num < self.config.dispather_min_idle_workers or len(self.workers) < self.config.dispather_min_workers or @@ -268,11 +274,15 @@ def request(self, method, host, path, headers, body, url=b"", timeout=60): if response and response.status == 200: self.success_num += 1 self.continue_fail_num = 0 + task.worker.continue_fail_tasks = 0 else: self.logger.warn("task %s %s %s timeout", method, host, path) self.fail_num += 1 self.continue_fail_num += 1 self.last_fail_time = time.time() + task.worker.continue_fail_tasks += 1 + if task.worker.continue_fail_tasks > self.config.dispather_worker_max_continue_fail: + self.trigger_create_worker_cv.notify() task.set_state("get_response") return response diff --git a/code/default/smart_router/local/pipe_socks.py b/code/default/smart_router/local/pipe_socks.py index 7324469171..1a5d25ece2 100644 --- a/code/default/smart_router/local/pipe_socks.py +++ b/code/default/smart_router/local/pipe_socks.py @@ -60,10 +60,12 @@ def add_socks(self, s1, s2): with self.sock_notify: s1.pair_sock = s2 s2.pair_sock = s1 - self.select2.register(s1, selectors.EVENT_READ) - self.select2.register(s2, selectors.EVENT_READ) - self.read_set.add(s1) - self.read_set.add(s2) + # self.select2.register(s1, selectors.EVENT_READ) + # self.select2.register(s2, selectors.EVENT_READ) + # self.read_set.add(s1) + # self.read_set.add(s2) + self.try_add("READ", s1) + self.try_add("READ", s2) self.sock_notify.notify() diff --git a/code/default/version.txt b/code/default/version.txt index acf69b48b8..3bff059174 100644 --- a/code/default/version.txt +++ b/code/default/version.txt @@ -1 +1 @@ -5.1.0 \ No newline at end of file +5.1.1 \ No newline at end of file diff --git a/code/default/x_tunnel/local/cloudflare_front/config.py b/code/default/x_tunnel/local/cloudflare_front/config.py index c832706d23..ef6b27da9e 100644 --- a/code/default/x_tunnel/local/cloudflare_front/config.py +++ b/code/default/x_tunnel/local/cloudflare_front/config.py @@ -15,7 +15,7 @@ def __init__(self, fn): self.set_var("dispather_work_min_idle_time", 0) self.set_var("dispather_work_max_score", 20000) self.set_var("dispather_min_workers", 1) - self.set_var("dispather_max_workers", 3) + self.set_var("dispather_max_workers", 8) self.set_var("dispather_score_factor", 1) # http 2 worker @@ -25,7 +25,7 @@ def __init__(self, fn): self.set_var("ssl_first_use_timeout", 5) self.set_var("connection_pool_min", 0) self.set_var("https_new_connect_num", 0) - self.set_var("connect_create_interval", 3) + self.set_var("connect_create_interval", 2) # check_ip self.set_var("check_ip_subdomain", "scan1")