def run_test_method(self, test_method, worker, logger, process_monitor): deadline = time.time() + self.args.duration azure_monitor_metric = AzureMonitorMetric( "Sync EventHubProducerClient") with worker: total_processed = 0 iter_processed = 0 start_time = time.perf_counter() while self.running and time.time() < deadline: try: cur_iter_start_time = time.perf_counter() processed = test_method(worker, self.args, logger, azure_monitor_metric) now_time = time.perf_counter() cur_iter_time_elapsed = now_time - cur_iter_start_time total_processed += processed iter_processed += processed if iter_processed >= self.args.output_interval: time_elapsed = now_time - start_time logger.info( "Total sent: %r, Time elapsed: %r, Speed: %r/s, Current Iteration Speed: %r/s", total_processed, time_elapsed, total_processed / time_elapsed, processed / cur_iter_time_elapsed) azure_monitor_metric.record_events_cpu_memory( iter_processed, process_monitor.cpu_usage_percent, process_monitor.memory_usage_percent) iter_processed -= self.args.output_interval except KeyboardInterrupt: logger.info("keyboard interrupted") self.stop() except Exception as e: logger.exception("%r failed:", type(worker), e) self.stop() logger.info("%r has finished testing", test_method)
def test_stress_queue_send_and_receive(): sb_client = ServiceBusClient.from_connection_string( SERVICE_BUS_CONNECTION_STR, logging_enable=LOGGING_ENABLE) stress_test = StressTestRunner( senders=[sb_client.get_queue_sender(SERVICEBUS_QUEUE_NAME)], receivers=[sb_client.get_queue_receiver(SERVICEBUS_QUEUE_NAME)], duration=timedelta(seconds=60), azure_monitor_metric=AzureMonitorMetric( "test_stress_queue_send_and_receive")) result = stress_test.run() assert (result.total_sent > 0) assert (result.total_received > 0)
def test_stress_queue_check_for_dropped_messages(): sb_client = ServiceBusClient.from_connection_string( SERVICE_BUS_CONNECTION_STR, logging_enable=LOGGING_ENABLE) stress_test = DroppedMessageCheckerStressTestRunner( senders=[sb_client.get_queue_sender(SERVICEBUS_QUEUE_NAME)], receivers=[sb_client.get_queue_receiver(SERVICEBUS_QUEUE_NAME)], receive_type=ReceiveType.pull, duration=timedelta(seconds=3000), azure_monitor_metric=AzureMonitorMetric( "test_stress_queue_check_for_dropped_messages")) result = stress_test.run() assert (result.total_sent > 0) assert (result.total_received > 0)
async def async_send(client, args): azure_monitor_metric = AzureMonitorMetric("Async ServiceBus Sender") process_monitor = ProcessMonitor("monitor_sender_stress_async.log", "sender_stress_async") stress_test = StressTestRunnerAsync( senders=[client.get_queue_sender(QUEUE_NAME)], receivers=[], message_size=args.message_size, send_batch_size=args.send_batch_size, duration=timedelta(seconds=args.duration), azure_monitor_metric=azure_monitor_metric, process_monitor=process_monitor, fail_on_exception=False) await stress_test.run_async()
async def async_receive(client, args): azure_monitor_metric = AzureMonitorMetric("Async ServiceBus Receiver") process_monitor = ProcessMonitor("monitor_receiver_stress_async.log", "receiver_stress_async") stress_test = StressTestRunnerAsync( senders=[], receivers=[client.get_queue_receiver(QUEUE_NAME)], max_message_count=args.max_message_count, receive_type=args.receive_type, max_wait_time=args.max_wait_time, duration=timedelta(seconds=args.duration), azure_monitor_metric=azure_monitor_metric, process_monitor=process_monitor, fail_on_exception=False) await stress_test.run_async()
def test_stress_queue_unsettled_messages(): sb_client = ServiceBusClient.from_connection_string( SERVICE_BUS_CONNECTION_STR, logging_enable=LOGGING_ENABLE) stress_test = StressTestRunner( senders=[sb_client.get_queue_sender(SERVICEBUS_QUEUE_NAME)], receivers=[sb_client.get_queue_receiver(SERVICEBUS_QUEUE_NAME)], duration=timedelta(seconds=350), should_complete_messages=False, azure_monitor_metric=AzureMonitorMetric( "test_stress_queue_unsettled_messages")) result = stress_test.run() # This test is prompted by reports of an issue where enough unsettled messages saturate a service-side cache # and prevent further receipt. assert (result.total_sent > 2500) assert (result.total_received > 2500)
args = parser.parse_args() starting_position = parse_starting_position(args) print_console = args.print_console or (os.environ.get("PRINT_CONSOLE") == "1") LOGGER = get_logger(args.log_filename, "stress_receive_sync", level=logging.INFO, print_console=print_console) LOG_PER_COUNT = args.output_interval start_time = time.perf_counter() recv_cnt_map = defaultdict(int) recv_cnt_iteration_map = defaultdict(int) recv_time_map = dict() azure_metric_monitor = AzureMonitorMetric("Sync EventHubConsumerClient") class EventHubConsumerClientTest(EventHubConsumerClient): def get_partition_ids(self): if args.partitions != 0: return [str(i) for i in range(args.partitions)] else: return super(EventHubConsumerClientTest, self).get_partition_ids() def on_event_received(process_monitor, partition_context, event): recv_cnt_map[partition_context.partition_id] += 1 if event else 0 if recv_cnt_map[partition_context.partition_id] % LOG_PER_COUNT == 0: total_time_elapsed = time.perf_counter() - start_time partition_previous_time = recv_time_map.get(