Skip to content

Commit 097718d

Browse files
committed
5.6.2 fix windows slow issue.
1 parent 541f58d commit 097718d

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

code/default/version.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.6.1
1+
5.6.2

code/default/x_tunnel/local/base_container.py

+26-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
import sys
13
import threading
24
import time
35
import socket
@@ -341,6 +343,12 @@ def __init__(self, session, xlog):
341343
self.sock_conn_map = {}
342344
self._lock = threading.RLock()
343345

346+
if sys.platform == "win32":
347+
self.slow_wait = 0.05
348+
else:
349+
self.slow_wait = 3
350+
# self.slow_wait = 0.05
351+
344352
def status(self):
345353
out_string = "ConnectionPipe:\r\n"
346354
out_string += " running: %s\r\n" % self.running
@@ -373,14 +381,18 @@ def add_sock_event(self, sock, conn, event):
373381

374382
with self._lock:
375383
self._debug_log("add_sock_event conn:%d event:%s", conn.conn_id, event)
376-
self.sock_conn_map[sock] = conn
377384
try:
378385
self.select2.register_event(sock, event, conn)
379386
except Exception as e:
380387
self.xlog.warn("add_sock_event %s conn:%d e:%r", sock, conn.conn_id, e)
381388
self.close_sock(sock, str(e) + "_when_add_sock_event")
382389
return
383390

391+
# if sys.platform == "win32" and (sock not in self.sock_conn_map or event == selectors.EVENT_WRITE):
392+
# self.notice_select()
393+
394+
self.sock_conn_map[sock] = conn
395+
384396
if not self.th:
385397
self.th = threading.Thread(target=self.pipe_worker, name="x_tunnel_pipe_worker")
386398
self.th.start()
@@ -438,6 +450,12 @@ def reset_all_connections(self):
438450
self.sock_conn_map = {}
439451
self.select2 = selectors.DefaultSelector()
440452

453+
def notice_select(self):
454+
self.xlog.debug("notice select")
455+
456+
def read_notify(self):
457+
self.xlog.debug("read_notify")
458+
441459
def pipe_worker(self):
442460
timeout = 0.001
443461
while self.running:
@@ -453,15 +471,15 @@ def pipe_worker(self):
453471
if has_data:
454472
timeout = 0.01
455473
else:
456-
timeout = 3.0
474+
timeout = self.slow_wait
457475

458476
# self.xlog.debug("%s recv select timeout switch to %f", random_id, timeout)
459477
continue
460478
else:
461479
# self.xlog.debug("%s recv select timeout switch to 0.001", random_id)
462480
timeout = 0.001
463481
except Exception as e:
464-
self.xlog.warn("Conn session:%s select except:%r", self.session.session_id, e)
482+
self.xlog.exception("Conn session:%s select except:%r", self.session.session_id, e)
465483
if "Invalid argument" in str(e):
466484
self.reset_all_connections()
467485
time.sleep(1)
@@ -471,6 +489,11 @@ def pipe_worker(self):
471489
for key, event in events:
472490
sock = key.fileobj
473491
conn = key.data
492+
if not conn:
493+
self.xlog.debug("get notice")
494+
self.read_notify()
495+
continue
496+
474497
if event & selectors.EVENT_READ:
475498
try:
476499
data = sock.recv(65535)

code/default/x_tunnel/local/proxy_session.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -706,13 +706,11 @@ def roundtrip_task(self, work_id):
706706
if lock_time > 0.1:
707707
xlog.warn("lock_time: %f", lock_time)
708708

709-
# if g.config.show_debug:
710-
# self.traffic_speed_calculation()
711-
# xlog.debug("start trip work_id:%d transfer_no:%d send_data_len:%d ack_len:%d timeout:%d",
712-
# work_id, transfer_no, send_data_len, send_ack_len, server_timeout)
713-
# xlog.debug("start trip, work_id:%d target:%d running:%d timeout:%d up:%f down:%f",
714-
# work_id, self.target_on_roads, self.on_road_num, server_timeout,
715-
# self.upload_speed, self.download_speed)
709+
if g.config.show_debug:
710+
self.traffic_speed_calculation()
711+
xlog.debug("start trip, tid:%d target:%d running:%d timeout:%d send:%d",
712+
transfer_no, self.target_on_roads, self.on_road_num, server_timeout,
713+
len(upload_post_data))
716714

717715
while self.running:
718716
try:

0 commit comments

Comments
 (0)