indexing description: "Benchmark Master" license: "MIT license (see ../../../license.txt)" author: "Beat Strasser " date: "$Date$" revision: "$Revision$" class P2P_BENCHMARK_MASTER inherit P2P_BENCHMARK P2P_RANDOM_SHARED create make feature -- Access is_master: BOOLEAN is True messages_count: INTEGER Wait_time: INTEGER_64 is 100000000 -- 100ms feature {NONE} -- Implementation arrived: DS_ARRAYED_LIST [BOOLEAN] data: DS_ARRAYED_LIST [STRING] start_benchmark is -- Main benchmark part local i, wait, wait_interval: INTEGER report: STRING do -- set number of messages to send if argument_count = 2 and argument (2).is_integer then messages_count := argument (2).to_integer else messages_count := 1000 end -- create test data logger.fatal ("benchmark master: creating test data") create arrived.make (messages_count) create data.make (messages_count) from i := 0 until i = messages_count loop arrived.put (False, i) data.put (create_random_string, i) i := i + 1 end -- send messages logger.fatal ("benchmark master: sending messages now, count: " + messages_count.out) from i := 0 until i = messages_count loop send_message (create_message (i)) if wait = 0 then sleep (wait_time) wait_interval := (rand.item \\ (messages_count // 2)) + 1 rand.forth end wait := (wait + 1) \\ wait_interval i := i + 1 end logger.fatal ("benchmark master: message sending completed") sleep (5000000000) send_stop_command -- finished: check for unreplied messages create report.make_empty from i := 0 until i = messages_count loop if not arrived.item (i) then report.append (i.out + " ") end i := i + 1 end -- report if report.count = 0 then logger.fatal ("benchmark master finished successfully") else logger.fatal ("benchmark master finished with errors! Missing packets: " + report) end end create_message (nr: INTEGER): P2P_MESSAGE is -- Create test message require Number_valid: nr >= 0 local elid, eldata: P2P_MESSAGE_ELEMENT do create elid.make_string (benchmark_element_namespace, benchmark_message_id, Void, nr.out) create eldata.make_string (benchmark_element_namespace, benchmark_message_data, Void, data.item (nr)) create Result.make Result.extend (elid) Result.extend (eldata) end benchmark_message_handler (a_msg: P2P_MESSAGE; a_source, a_destination: P2P_ENDPOINT_ADDRESS) is -- Benchmark message handler local elid, eldata: P2P_MESSAGE_ELEMENT nr: INTEGER do -- message number elid := a_msg.element_by_namespace_and_name (benchmark_element_namespace, benchmark_message_id) if elid /= Void and elid.content.is_integer then nr := elid.content.to_integer if not arrived.item (nr) then -- content eldata := a_msg.element_by_namespace_and_name (benchmark_element_namespace, benchmark_message_data) if eldata /= Void and eldata.type.is_equal (eldata.type_textplain_utf8) then if eldata.content.is_equal (data.item (nr).as_upper) then logger.debugging ("benchmark master: Received reply for message: " + nr.out) arrived.replace (True, nr) end end end end end send_stop_command is -- Send stop command to slave local msg: P2P_MESSAGE control: P2P_MESSAGE_ELEMENT do create msg.make create control.make (benchmark_element_namespace, benchmark_control, Void, Void, benchmark_control_stop) msg.extend (control) send_message (msg) end create_random_string: STRING is -- Create a random string local i, char: INTEGER do from i := (rand.item \\ 200) + 5 rand.forth create Result.make (i) until i = 0 loop char := (rand.item \\ 26) + 97 rand.forth Result.append_character (char.to_character_8) i := i - 1 end end end