Skip to content

Commit

Permalink
5.6.2 fix windows slow issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-X-Net committed Sep 2, 2023
1 parent 541f58d commit 097718d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
2 changes: 1 addition & 1 deletion code/default/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.6.1
5.6.2
29 changes: 26 additions & 3 deletions code/default/x_tunnel/local/base_container.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os
import sys
import threading
import time
import socket
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -373,14 +381,18 @@ 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:
self.xlog.warn("add_sock_event %s conn:%d e:%r", sock, conn.conn_id, e)
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()
Expand Down Expand Up @@ -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:
Expand All @@ -453,15 +471,15 @@ 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
else:
# 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)
Expand All @@ -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)
Expand Down
12 changes: 5 additions & 7 deletions code/default/x_tunnel/local/proxy_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 097718d

Please sign in to comment.