s1042992 / MaplePing

Ping tool for Maplestory
0 stars 3 forks source link

Multithread version #1

Open s1042992 opened 2 years ago

s1042992 commented 2 years ago
import os
import time 
from tcp_latency import measure_latency
import numpy as np
import threading
channel_rtt = np.array(range(40), np.float)
def get_ip(ch):
    if ch > 30:
        ip = "202.80.104." + str(((ch - 30) // 2) + 154) # only happens in world 0 
    else:
        ip = "202.80.104." + str((ch // 2) + init)
    return ip

def get_port(ch):
    if ch % 2 == 0:
        return 8585
    else:
        return 8686
def ping_job(channel):
    result = measure_latency(host = get_ip(channel), port = get_port(channel))
    if result is None:
        result = 999999 
    channel_rtt[channel] = round(result[0],3)
    print("CH.", channel + 1,"= ", channel_rtt[channel], "ms")

if __name__ == '__main__':
    print("******************")
    print("伺服器         編號")
    print()
    print("艾麗亞:      0")
    print("普力特:      1")
    print("琉德:       2")
    print("優依娜:      3")
    print("愛麗西亞:     4")
    print("殺人鯨:      6")
    print("Reboot:      45")
    print()
    print("******************")
    print("上面是每個伺服器對應的編號,請輸入編號來查看本機與伺服器之間延遲狀況:")
    print("(Here is the list of world, please enter a world number)")
    w = {0, 1, 2, 3, 4, 6, 45}
    while True:
        world = input()
        try:
            world = int(world)
            if world in w:
                print("Please wait for a while...")
                break
            else:
                print("Please re-enter a legal world number:")
                continue
        except:
            print("Please re-enter a legal world number:")
            continue

    if world == 6: # there's no world 5
        world = world - 1

    if world == 45: #World Reboot is very special...
        init = 164
        dungeon_ip = "202.80.104.39"
        mall_ip = "202.80.104.47"
    else:
        init = 64 + world * 15
        dungeon_ip = "202.80.104." + str(32 + world)
        mall_ip = "202.80.104." + str(40 + world)
        auction_ip = "202.80.104." + str(40 + world)

    thread_list = []
    if world == 0: #World 0 has 40 channels
        try:
            for i in range(40):
                t = threading.Thread(target = ping_job, args=(i,))
                thread_list.append(t)

        except:
            pass
    else:
        try:
            for i in range(30):
                t = threading.Thread(target = ping_job, args=(i,))
                thread_list.append(t)
        except:
            pass

    for i in thread_list: 
        i.start()

    for i in thread_list: 
        i.join()

    print("副本: ", round(measure_latency(dungeon_ip, 8686)[0],3), "ms")
    print("商城: ", round(measure_latency(mall_ip, 8686)[0],3), "ms")

    if world != 45: #World Reboot has no Auction system
        print("拍賣: ", round(measure_latency(auction_ip, 8787)[0],3), "ms")

    channel_rtt = channel_rtt.tolist()
    if world != 0:   
        max_value = max(channel_rtt[0:30])
        min_value = min(channel_rtt[0:30])
    else:
        max_value = max(channel_rtt)
        min_value = min(channel_rtt)

    print()
    print("Maximum delay CH.", channel_rtt.index(max_value)+1, ",RTT = ", max_value, "ms")
    print("Minimal delay CH.", channel_rtt.index(min_value)+1, ",RTT = ", min_value, "ms")
    print("建議去 CH.",channel_rtt.index(min_value)+1)
    print()
    os.system("pause")

In python, I created a thread list and append the 40 times ping works measure_latency(host, port) into the list, then the result was like:

CH. 3 =  15.075 ms
CH. 17 =  20.111 ms
CH. 16 =  20.111 ms
CH. 4 =  20.593 ms
CH. 9 =  20.111 ms
CH. 14 =  21.094 ms
CH. 6 =  20.595 ms
CH. 8 =  20.595 ms
CH. 7 =  24.604 ms
CH. 11 =  20.111 ms
CH. 13 =  24.606 ms
CH. 10 =  25.609 ms
CH. 12 =  20.094 ms
CH. 2 =  25.104 ms
CH. 15 =  25.107 ms
CH. 35 =  25.105 ms
CH. 32 =  29.118 ms
CH. 1 =  25.104 ms
CH. 29 =  29.117 ms
CH. 24 =  33.128 ms
CH. 5 =  35.132 ms
CH. 31 =  29.117 ms
CH. 20 =  34.632 ms
CH. 21 =  35.633 ms
CH. 22 =  33.628 ms
CH. 36 =  34.129 ms
CH. 30 =  38.139 ms
CH. 26 =  38.641 ms
CH. 18 =  38.641 ms
CH. 25 =  39.142 ms
CH. 33 =  36.134 ms
CH. 28 =  38.641 ms
CH. 40 =  43.153 ms
CH. 34 =  35.132 ms
CH. 37 =  44.158 ms
CH. 23 =  25.607 ms
CH. 38 =  42.652 ms
CH. 39 =  44.158 ms
CH. 19 =  34.632 ms
CH. 27 =  39.142 ms

The RTT time above somehow progressively increases. any solution will be greatful

shamil03 commented 2 years ago

import os import time from tcp_latency import measure_latency import numpy as np import threading channel_rtt = np.array(range(40), np.float) def get_ip(ch): if ch > 30: ip = "202.80.104." + str(((ch - 30) // 2) + 154) # only happens in world 0 else: ip = "202.80.104." + str((ch // 2) + init) return ip

def get_port(ch): if ch % 2 == 0: return 8585 else: return 8686 def ping_job(channel): result = measure_latency(host = get_ip(channel), port = get_port(channel)) if result is None: result = 999999 channel_rtt[channel] = round(result[0],3) print("CH.", channel + 1,"= ", channel_rtt[channel], "ms")

if name == 'main': print("**") print("伺服器 編號") print() print("艾麗亞: 0") print("普力特: 1") print("琉德: 2") print("優依娜: 3") print("愛麗西亞: 4") print("殺人鯨: 6") print("Reboot: 45") print() print("**") print("上面是每個伺服器對應的編號,請輸入編號來查看本機與伺服器之間延遲狀況:") print("(Here is the list of world, please enter a world number)") w = {0, 1, 2, 3, 4, 6, 45} while True: world = input() try: world = int(world) if world in w: print("Please wait for a while...") break else: print("Please re-enter a legal world number:") continue except: print("Please re-enter a legal world number:") continue

if world == 6: # there's no world 5
    world = world - 1

if world == 45: #World Reboot is very special...
    init = 164
    dungeon_ip = "202.80.104.39"
    mall_ip = "202.80.104.47"
else:
    init = 64 + world * 15
    dungeon_ip = "202.80.104." + str(32 + world)
    mall_ip = "202.80.104." + str(40 + world)
    auction_ip = "202.80.104." + str(40 + world)

thread_list = []
if world == 0: #World 0 has 40 channels
    try:
        for i in range(40):
            t = threading.Thread(target = ping_job, args=(i,))
            thread_list.append(t)

    except:
        pass
else:
    try:
        for i in range(30):
            t = threading.Thread(target = ping_job, args=(i,))
            thread_list.append(t)
    except:
        pass

for i in thread_list: 
    i.start()

for i in thread_list: 
    i.join()

print("副本: ", round(measure_latency(dungeon_ip, 8686)[0],3), "ms")
print("商城: ", round(measure_latency(mall_ip, 8686)[0],3), "ms")

if world != 45: #World Reboot has no Auction system
    print("拍賣: ", round(measure_latency(auction_ip, 8787)[0],3), "ms")

channel_rtt = channel_rtt.tolist()
if world != 0:   
    max_value = max(channel_rtt[0:30])
    min_value = min(channel_rtt[0:30])
else:
    max_value = max(channel_rtt)
    min_value = min(channel_rtt)

print()
print("Maximum delay CH.", channel_rtt.index(max_value)+1, ",RTT = ", max_value, "ms")
print("Minimal delay CH.", channel_rtt.index(min_value)+1, ",RTT = ", min_value, "ms")
print("建議去 CH.",channel_rtt.index(min_value)+1)
print()
os.system("pause")
s1042992 commented 2 years ago

I'm not sure if the code you left works, maybe you should leave more information about it. @shamil03