Skip to content

更准确的网络丢包数据以及更快的数据收敛 #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ping_thread, prefer ipv4 first
  • Loading branch information
kings-way committed Jun 18, 2021
commit 05f9784b1ef592092a2affb13b551e35ed495d48
23 changes: 17 additions & 6 deletions clients/client-linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
PORT = 35601
PASSWORD = "USER_DEFAULT_PASSWORD"
INTERVAL = 1
PORBEPORT = 80
PROBEPORT = 80
PROBE_PROTOCOL_PREFER = "ipv4" # ipv4, ipv6
PING_PACKET_HISTORY_LEN = 100
CU = "cu.tz.cloudcpp.com"
CT = "ct.tz.cloudcpp.com"
Expand Down Expand Up @@ -121,7 +122,7 @@ def ip_status():
ip_check = 0
for i in [CU, CT, CM]:
try:
socket.create_connection((i, PORBEPORT), timeout=1).close()
socket.create_connection((i, PROBEPORT), timeout=1).close()
except:
ip_check += 1
if ip_check >= 2:
Expand Down Expand Up @@ -163,13 +164,23 @@ def _ping_thread(host, mark, port):
lostPacket = 0
packet_queue = Queue(maxsize=PING_PACKET_HISTORY_LEN)

IP = host
if host.count(':') < 1: # if not plain ipv6 address, means ipv4 address or hostname
try:
if PROBE_PROTOCOL_PREFER == 'ipv4':
IP = socket.getaddrinfo(host, None, socket.AF_INET)[0][4][0]
else:
IP = socket.getaddrinfo(host, None, socket.AF_INET6)[0][4][0]
except Exception:
pass

while True:
if packet_queue.full():
if packet_queue.get() == 0:
lostPacket -= 1
try:
b = timeit.default_timer()
socket.create_connection((host, port), timeout=1).close()
socket.create_connection((IP, port), timeout=1).close()
pingTime[mark] = int((timeit.default_timer()-b)*1000)
packet_queue.put(1)
except:
Expand Down Expand Up @@ -212,23 +223,23 @@ def get_realtime_date():
kwargs={
'host': CU,
'mark': '10010',
'port': PORBEPORT
'port': PROBEPORT
}
)
t2 = threading.Thread(
target=_ping_thread,
kwargs={
'host': CT,
'mark': '189',
'port': PORBEPORT
'port': PROBEPORT
}
)
t3 = threading.Thread(
target=_ping_thread,
kwargs={
'host': CM,
'mark': '10086',
'port': PORBEPORT
'port': PROBEPORT
}
)
t4 = threading.Thread(
Expand Down
23 changes: 17 additions & 6 deletions clients/client-psutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
PORT = 35601
PASSWORD = "USER_DEFAULT_PASSWORD"
INTERVAL = 1
PORBEPORT = 80
PROBEPORT = 80
PROBE_PROTOCOL_PREFER = "ipv4" # ipv4, ipv6
PING_PACKET_HISTORY_LEN = 100
CU = "cu.tz.cloudcpp.com"
CT = "ct.tz.cloudcpp.com"
Expand Down Expand Up @@ -106,7 +107,7 @@ def ip_status():
ip_check = 0
for i in [CU, CT, CM]:
try:
socket.create_connection((i, PORBEPORT), timeout=1).close()
socket.create_connection((i, PROBEPORT), timeout=1).close()
except:
ip_check += 1
if ip_check >= 2:
Expand Down Expand Up @@ -148,13 +149,23 @@ def _ping_thread(host, mark, port):
lostPacket = 0
packet_queue = Queue(maxsize=PING_PACKET_HISTORY_LEN)

IP = host
if host.count(':') < 1: # if not plain ipv6 address, means ipv4 address or hostname
try:
if PROBE_PROTOCOL_PREFER == 'ipv4':
IP = socket.getaddrinfo(host, None, socket.AF_INET)[0][4][0]
else:
IP = socket.getaddrinfo(host, None, socket.AF_INET6)[0][4][0]
except Exception:
pass

while True:
if packet_queue.full():
if packet_queue.get() == 0:
lostPacket -= 1
try:
b = timeit.default_timer()
socket.create_connection((host, port), timeout=1).close()
socket.create_connection((IP, port), timeout=1).close()
pingTime[mark] = int((timeit.default_timer() - b) * 1000)
packet_queue.put(1)
except:
Expand Down Expand Up @@ -193,23 +204,23 @@ def get_realtime_date():
kwargs={
'host': CU,
'mark': '10010',
'port': PORBEPORT
'port': PROBEPORT
}
)
t2 = threading.Thread(
target=_ping_thread,
kwargs={
'host': CT,
'mark': '189',
'port': PORBEPORT
'port': PROBEPORT
}
)
t3 = threading.Thread(
target=_ping_thread,
kwargs={
'host': CM,
'mark': '10086',
'port': PORBEPORT
'port': PROBEPORT
}
)
t4 = threading.Thread(
Expand Down