-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathrepro_concurrency.py
More file actions
49 lines (39 loc) · 1.58 KB
/
Copy pathrepro_concurrency.py
File metadata and controls
49 lines (39 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import os
import statistics
import sys
import time
sys.path.insert(0, os.path.join(os.getcwd(), 'src'))
from stage3.engine import get_engine
from stage3.metrics import get_summary
from constants import V2RAY_CORE_PATH, STAGE3_BACKEND
def main() -> int:
if not V2RAY_CORE_PATH or not os.path.exists(V2RAY_CORE_PATH):
print(f"Xray core not found at {V2RAY_CORE_PATH}")
return 1
test_uri = (
"vless://00000000-0000-0000-0000-000000000000@1.2.3.4:443"
"?encryption=none&security=tls&type=tcp#Test"
)
n = int(os.environ.get('OPENRAY_REPRO_N', '10'))
timeout_s = int(os.environ.get('OPENRAY_REPRO_TIMEOUT', '15'))
print(f"Backend={STAGE3_BACKEND} core={V2RAY_CORE_PATH} n={n} timeout={timeout_s}s")
engine = get_engine(force_new=True)
durations: list = []
t0 = time.perf_counter()
for _ in range(n):
start = time.perf_counter()
res = engine.validate_one(test_uri, timeout_s=timeout_s)
durations.append(time.perf_counter() - start)
print(f" result={res} duration={durations[-1]:.2f}s")
elapsed = time.perf_counter() - t0
summary = get_summary()
print(f"\nTotal wall: {elapsed:.2f}s")
if durations:
print(f"p50={statistics.median(durations):.2f}s p95={sorted(durations)[int(len(durations)*0.95)]:.2f}s")
print(f"proxies_per_min={(n / elapsed) * 60:.1f}" if elapsed > 0 else "proxies_per_min=0")
if summary:
print(summary.format_line())
engine.shutdown()
return 0
if __name__ == '__main__':
raise SystemExit(main())