From 097718d0cabda7b9a4264e0cf7d9205ffb2b5fc6 Mon Sep 17 00:00:00 2001 From: micheal Date: Sat, 2 Sep 2023 17:11:39 +1200 Subject: [PATCH] 5.6.2 fix windows slow issue. --- code/default/version.txt | 2 +- code/default/x_tunnel/local/base_container.py | 29 +++++++++++++++++-- code/default/x_tunnel/local/proxy_session.py | 12 ++++---- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/code/default/version.txt b/code/default/version.txt index 566ac6388b..475e184294 100644 --- a/code/default/version.txt +++ b/code/default/version.txt @@ -1 +1 @@ -5.6.1 \ No newline at end of file +5.6.2 \ No newline at end of file diff --git a/code/default/x_tunnel/local/base_container.py b/code/default/x_tunnel/local/base_container.py index d35af5f540..7136ce7199 100644 --- a/code/default/x_tunnel/local/base_container.py +++ b/code/default/x_tunnel/local/base_container.py @@ -1,3 +1,5 @@ +import os +import sys import threading import time import socket @@ -341,6 +343,12 @@ def __init__(self, session, xlog): self.sock_conn_map = {} self._lock = threading.RLock() + if sys.platform == "win32": + self.slow_wait = 0.05 + else: + self.slow_wait = 3 + # self.slow_wait = 0.05 + def status(self): out_string = "ConnectionPipe:\r\n" out_string += " running: %s\r\n" % self.running @@ -373,7 +381,6 @@ def add_sock_event(self, sock, conn, event): with self._lock: self._debug_log("add_sock_event conn:%d event:%s", conn.conn_id, event) - self.sock_conn_map[sock] = conn try: self.select2.register_event(sock, event, conn) except Exception as e: @@ -381,6 +388,11 @@ def add_sock_event(self, sock, conn, event): self.close_sock(sock, str(e) + "_when_add_sock_event") return + # if sys.platform == "win32" and (sock not in self.sock_conn_map or event == selectors.EVENT_WRITE): + # self.notice_select() + + self.sock_conn_map[sock] = conn + if not self.th: self.th = threading.Thread(target=self.pipe_worker, name="x_tunnel_pipe_worker") self.th.start() @@ -438,6 +450,12 @@ def reset_all_connections(self): self.sock_conn_map = {} self.select2 = selectors.DefaultSelector() + def notice_select(self): + self.xlog.debug("notice select") + + def read_notify(self): + self.xlog.debug("read_notify") + def pipe_worker(self): timeout = 0.001 while self.running: @@ -453,7 +471,7 @@ def pipe_worker(self): if has_data: timeout = 0.01 else: - timeout = 3.0 + timeout = self.slow_wait # self.xlog.debug("%s recv select timeout switch to %f", random_id, timeout) continue @@ -461,7 +479,7 @@ def pipe_worker(self): # self.xlog.debug("%s recv select timeout switch to 0.001", random_id) timeout = 0.001 except Exception as e: - self.xlog.warn("Conn session:%s select except:%r", self.session.session_id, e) + self.xlog.exception("Conn session:%s select except:%r", self.session.session_id, e) if "Invalid argument" in str(e): self.reset_all_connections() time.sleep(1) @@ -471,6 +489,11 @@ def pipe_worker(self): for key, event in events: sock = key.fileobj conn = key.data + if not conn: + self.xlog.debug("get notice") + self.read_notify() + continue + if event & selectors.EVENT_READ: try: data = sock.recv(65535) diff --git a/code/default/x_tunnel/local/proxy_session.py b/code/default/x_tunnel/local/proxy_session.py index 93c4f55753..9537cec8cb 100644 --- a/code/default/x_tunnel/local/proxy_session.py +++ b/code/default/x_tunnel/local/proxy_session.py @@ -706,13 +706,11 @@ def roundtrip_task(self, work_id): if lock_time > 0.1: xlog.warn("lock_time: %f", lock_time) - # if g.config.show_debug: - # self.traffic_speed_calculation() - # xlog.debug("start trip work_id:%d transfer_no:%d send_data_len:%d ack_len:%d timeout:%d", - # work_id, transfer_no, send_data_len, send_ack_len, server_timeout) - # xlog.debug("start trip, work_id:%d target:%d running:%d timeout:%d up:%f down:%f", - # work_id, self.target_on_roads, self.on_road_num, server_timeout, - # self.upload_speed, self.download_speed) + if g.config.show_debug: + self.traffic_speed_calculation() + xlog.debug("start trip, tid:%d target:%d running:%d timeout:%d send:%d", + transfer_no, self.target_on_roads, self.on_road_num, server_timeout, + len(upload_post_data)) while self.running: try: