-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add simple message size test federation
- Loading branch information
1 parent
6689686
commit 92ccf84
Showing
3 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
unmaintained/python/helics_message_size/long_message_receiver.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on 19 Nove 2024 | ||
Test federation to evaluate any message size limits of HELICS. | ||
This federate receives the bytes and based on the granted time, | ||
validates that all bytes sent have been received. | ||
The message size is 10000 times the size of the granted time. | ||
@author: Trevor Hardy | ||
[email protected] | ||
""" | ||
|
||
import helics as h | ||
import logging | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
logger.addHandler(logging.StreamHandler()) | ||
logger.setLevel(logging.DEBUG) | ||
|
||
|
||
if __name__ == "__main__": | ||
time_requests = [1, 10, 100, 1000, 10000, 100000, 1000000] | ||
|
||
fedinfo = h.helicsCreateFederateInfo() | ||
fedinfo.core_name = "long_message_receiver_core" | ||
fedinfo.core_type = "zmq" | ||
fed = h.helicsCreateCombinationFederate("LongMessageReceiver", fedinfo) | ||
fed.register_global_endpoint("receiver_ep") | ||
fed.property[h.HELICS_PROPERTY_TIME_PERIOD] = 0.0001 | ||
fed.flag[h.HELICS_FLAG_WAIT_FOR_CURRENT_TIME_UPDATE] = True | ||
|
||
fed.enter_executing_mode() | ||
|
||
for time in time_requests: | ||
granted_time = fed.request_time(time) | ||
intended_message_size = granted_time * 1000 | ||
if fed.endpoints["receiver_ep"].has_message: | ||
helics_message = fed.endpoints["receiver_ep"].get_message() | ||
message_str = helics_message.data | ||
message_num_char = len(message_str) | ||
if message_num_char == intended_message_size: | ||
logger.debug(f"Full message received of size {int(intended_message_size)}") | ||
else: | ||
logger.error(f"Incomplete message received of size {int(message_num_char)} out of {int(intended_message_size)}") | ||
else: | ||
logger.debug(f"No message waiting at time {granted_time}") | ||
|
||
h.helicsFederateDestroy(fed) | ||
h.helicsCloseLibrary() | ||
|
47 changes: 47 additions & 0 deletions
47
unmaintained/python/helics_message_size/long_message_sender.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on 19 Nove 2024 | ||
Test federation to evaluate any message size limits of HELICS. | ||
This federate will send a message (string) of increasing size | ||
and the other federate will recieve it and check the size. | ||
The message size is 10000 times the size of the granted time. | ||
@author: Trevor Hardy | ||
[email protected] | ||
""" | ||
|
||
import helics as h | ||
import logging | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
logger.addHandler(logging.StreamHandler()) | ||
logger.setLevel(logging.DEBUG) | ||
|
||
|
||
if __name__ == "__main__": | ||
time_requests = [1, 10, 100, 1000, 10000, 100000, 1000000] | ||
|
||
fedinfo = h.helicsCreateFederateInfo() | ||
fedinfo.core_name = "long_message_sender_core" | ||
fedinfo.core_type = "zmq" | ||
fed = h.helicsCreateCombinationFederate("LongMessageSender", fedinfo) | ||
fed.register_global_endpoint("sender_ep") | ||
fed.property[h.HELICS_PROPERTY_TIME_PERIOD] = 0.0001 | ||
fed.flag[h.HELICS_FLAG_WAIT_FOR_CURRENT_TIME_UPDATE] = False | ||
|
||
fed.enter_executing_mode() | ||
|
||
for time in time_requests: | ||
granted_time = fed.request_time(time) | ||
message_size = int(granted_time) * 1000 | ||
send_string = 'x' * message_size | ||
fed.endpoints["sender_ep"].send_data(send_string, "receiver_ep") | ||
logger.info(f"Sent message of length {message_size}") | ||
|
||
h.helicsFederateDestroy(fed) | ||
h.helicsCloseLibrary() | ||
|
18 changes: 18 additions & 0 deletions
18
unmaintained/python/helics_message_size/runner_long_message.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "Long message test", | ||
"broker": true, | ||
"federates": [ | ||
{ | ||
"directory": ".", | ||
"exec": "python -u long_message_sender.py", | ||
"host": "localhost", | ||
"name": "long_message_sender" | ||
}, | ||
{ | ||
"directory": ".", | ||
"exec": "python -u long_message_receiver.py", | ||
"host": "localhost", | ||
"name": "long_message_receiver" | ||
} | ||
] | ||
} |