from multiprocessing import Process, Manager import time from reem import RedisInterface, CallbackSubscriber, PublishSpace from tests.testing import plot_performance interface = RedisInterface() publisher = PublishSpace(interface) class Subscriber(Process): def __init__(self): self.manager = Manager() self.time_list = self.manager.list([]) self.kill = False self.subscriber = None self.last_time = time.time() + 1 super().__init__() def callback(self, data, updated_path): sent_time = data["timestamp"] self.time_list.append((time.time() - sent_time) * 1000) self.last_time = time.time() # print("Called") def run(self): self.subscriber = CallbackSubscriber("pub_sub_performance_test", interface, self.callback, {}) self.subscriber.listen() while time.time() - self.last_time < 1: # print(len(self.time_list)) pass print("Killed")
logging.basicConfig(format=FORMAT) logger = logging.getLogger("reem") logger.setLevel(logging.DEBUG) image_array = np.random.rand(640, 480, 3) flat_data = get_flat_data() nested_data = get_nested_data() image_dict = {"image": image_array} hundred_key_dict = single_level_dictionary() layered_dictionary = nested_level_dictionary(levels=3) interface = RedisInterface(host="localhost") interface.initialize() pspace = PublishSpace(interface) pspace.track_schema_changes(True) active = SilentSubscriber("channel", interface) active.listen() def test_active_update_basic(): pspace["channel"] = flat_data time.sleep(.05) assert str(active.value()) == str(flat_data) def test_active_update_sequence(): test_active_update_basic() pspace["channel"]["subkey"] = flat_data time.sleep(.01)
def overhead_testing_publisher(): interface = RedisInterface() publisher = PublishSpace(interface) for i in range(TRIALS): publisher["overhead_test"] = {"timestamp": time.time()} time.sleep(PULSE_GAP)
import logging # Logging Configuration logging.basicConfig( format= "%(asctime)20s %(filename)30s:%(lineno)3s %(funcName)20s() %(levelname)10s %(message)s", filename="controller_silent_subcsriber.log", filemode='w') logger = logging.getLogger("script") logger.setLevel(logging.INFO) TIME_TO_RUN = 10.0 # seconds # --------------------------- Main ----------------------------------- pspace = PublishSpace("localhost") set_frequency = 100 # Hz set_period = 1.0 / set_frequency print("Writting to channel 'command' for", TIME_TO_RUN, "seconds...") print("(Run actuator.py at the same time)") num_messages = 0 start_time = time.time() next_iteration = time.time() while time.time() < start_time + TIME_TO_RUN: #this does the publishing command = time.time() pspace["command"] = command logger.info("Published Set Point: {}".format(command))
from reem import PublishSpace, CallbackSubscriber import time import os # Initialize a publisher publisher = PublishSpace("localhost") t0 = None # Callback Function def callback(data, updated_path, foo): global t0 print("Received message from publisher, delay", time.time() - t0) print("Foo = {}".format(foo)) print("Updated Path = {}".format(updated_path)) print("Data = {}".format(data)) # # Initialize a callback subscriber subscriber = CallbackSubscriber(channel="callback_channel", interface="localhost", callback_function=callback, kwargs={"foo": 5}) subscriber.listen() t0 = time.time() publisher["callback_channel"] = {"number": 5, "string": "REEM"} #windows is sometimes ungodly slow at setting up an initial connection... if you have problems uncomment the following line if os.name == 'nt': time.sleep(2.0)