-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathone_to_many.py
More file actions
68 lines (51 loc) · 2.02 KB
/
one_to_many.py
File metadata and controls
68 lines (51 loc) · 2.02 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import os
import time
import liner
module_path = os.path.dirname(os.path.abspath(__file__))
liner.loadLib(module_path + "/../target/release/libliner_broker.so")
MESS_SEND_COUNT = 10
MESS_SIZE = 100
SEND_CYCLE_COUNT = 10
receive_count_client1 = 0
receive_count_client2 = 0
send_begin = time.time()
send_end = time.time()
def receive_cback1(to: str, from_: str, data):
global receive_count_client2
receive_count_client2 += 1
def receive_cback2(to: str, from_: str, data: bytes):
global receive_count_client1
receive_count_client1 += 1
def receive_cback_server(to: str, from_: str, data: bytes):
pass
def func():
hClient1 = liner.Client("client1", "topic_client", "localhost:2255", "redis://localhost/")
hClient2 = liner.Client("client2", "topic_client", "localhost:2256", "redis://localhost/")
hServer1 = liner.Client("server1", "topic_server1", "localhost:2257", "redis://localhost/")
hServer1.clear_stored_messages()
hClient1.clear_stored_messages()
hClient2.clear_stored_messages()
hServer1.clear_addresses_of_topic()
hClient1.clear_addresses_of_topic()
hClient2.clear_addresses_of_topic()
if not hClient1.run(receive_cback1):
raise Exception('hClient1 error no run')
if not hClient2.run(receive_cback2):
raise Exception('hClient2 error no run')
if not hServer1.run(receive_cback_server):
raise Exception('hServer1 error no run')
b = bytearray(MESS_SIZE)
global send_end
for i in range(SEND_CYCLE_COUNT):
send_begin = time.time()
for j in range(MESS_SEND_COUNT):
if not hServer1.send_all("topic_client", b):
raise Exception('error send_all')
send_end = time.time()
print("send_to", round((send_end - send_begin) * 1000, 3), "ms")
time.sleep(1)
global receive_count_client1, receive_count_client2
print("receive_count_client1", receive_count_client1)
print("receive_count_client2", receive_count_client2)
print("end")
func()