def test_transfered_ongoing_non_continues_ops(): ticket = Ticket(testutil.create_ticket(ops=["read"])) # Start 2 ongoing operations. # ongoing: 0-0, 200-200 # completed: op1 = Operation(0, 100) op2 = Operation(200, 100) ticket._add_operation(op1) ticket._add_operation(op2) assert ticket.transferred() == 0 assert ticket.active() # Consume op1 data: # ongoing: 0-100, 200-200 # completed: op1.run() ticket._remove_operation(op1) assert ticket.transferred() == 100 # Consume op2 data: # ongoing: 0-100, 200-300 # completed: op2.run() ticket._remove_operation(op2) assert ticket.transferred() == 200
def test_transfered_inactive_empty_ops(): ticket = Ticket(testutil.create_ticket(ops=["read"])) ticket.run(Operation(0, 0)) assert ticket.transferred() == 0 ticket.run(Operation(1000, 0)) assert ticket.transferred() == 0
def test_transfered_ongoing_overlapping_ops(): ticket = Ticket(testutil.create_ticket(ops=["read"])) # Start 2 ongoing operations. # ongoing: 0-0, 80-80 # completed: op1 = Operation(0, 120) op2 = Operation(80, 120) ticket._add_operation(op1) ticket._add_operation(op2) assert ticket.transferred() == 0 assert ticket.active() # Consume op1 data: # ongoing: 0-120, 80-80 # completed: op1.run() ticket._remove_operation(op1) assert ticket.transferred() == 120 assert ticket.active() # Consume op2 data: # ongoing: 0-120, 80-200 # completed: op2.run() ticket._remove_operation(op2) assert ticket.transferred() == 200 assert not ticket.active()
def test_transfered_ongoing_concurrent_ops(cfg): ticket = Ticket(testutil.create_ticket(ops=["read"]), cfg) # Start 2 ongoing operations: # ongoing: 0-0, 100-100 # completed: op1 = Operation(0, 100) ticket._add_operation(op1) assert ticket.transferred() == 0 assert ticket.active() op2 = Operation(100, 100) ticket._add_operation(op2) assert ticket.transferred() == 0 assert ticket.active() # Consume op1 data: # ongoing: 0-100, 100-100 # completed: op1.run() ticket._remove_operation(op1) assert ticket.transferred() == 100 assert ticket.active() # Consume op2 data: # ongoing: 0-100, 100-200 # completed: op2.run() ticket._remove_operation(op2) assert ticket.transferred() == 200 assert not ticket.active()
def test_transfered_inactive_non_continuous_ops(): ticket = Ticket(testutil.create_ticket(ops=["read"])) # Run 2 non-continutes operations ticket.run(Operation(0, 100)) ticket.run(Operation(200, 100)) assert ticket.transferred() == 200 # Run last operation filling the hole - with some overlap. ticket.run(Operation(80, 120)) assert ticket.transferred() == 300
def test_transfered_inactive_overlapping_ops(): ticket = Ticket(testutil.create_ticket(ops=["read"])) ticket.run(Operation(0, 120)) assert ticket.transferred() == 120 ticket.run(Operation(100, 100)) assert ticket.transferred() == 200 ticket.run(Operation(180, 120)) assert ticket.transferred() == 300
def test_transfered_inactive_unordered_ops(): ticket = Ticket(testutil.create_ticket(ops=["read"])) ticket.run(Operation(100, 100)) assert ticket.transferred() == 100 ticket.run(Operation(0, 100)) assert ticket.transferred() == 200 ticket.run(Operation(200, 100)) assert ticket.transferred() == 300
def test_ticket_run(): ticket = Ticket(testutil.create_ticket(ops=["read"])) op = Operation(0, 100) assert ticket.transferred() == op.done assert op.done == 0 ticket.run(op) assert ticket.transferred() == op.done assert op.done == 100
def test_run_benchmark(cfg, workers, client_class, mode): ticket = Ticket(testutil.create_ticket(size=100 * 1024**3, ops=mode), cfg) client = client_class(ticket, workers) elapsed = client.run() if mode != ["read", "write"]: assert ticket.transferred() == ticket.size ops = ticket.size // client.io_size print("%d workers, %d ops, %.3f s, %.2f ops/s" % (client.workers, ops, elapsed, ops / elapsed))
def test_transferred_benchmark(concurrent): # Time trransferred call with multiple ongoing and completed operations. ticket = Ticket(testutil.create_ticket(ops=["read"])) calls = 10000 # Add some completed ranges - assume worst case when ranges are not # continues. for i in range(concurrent): ticket.run(Operation(i * 1000, 100)) # Add some ongoing operations - assume worst case when ranges are not # continues. for i in range(concurrent): ticket._add_operation(Operation(i * 1000 + 200, 100)) # Time transferred call - merging ongoing and completed ranges. start = time.monotonic() for i in range(calls): ticket.transferred() elapsed = time.monotonic() - start print("%d concurrent operations, %d calls in %.3f seconds (%d nsec/op)" % (concurrent, calls, elapsed, elapsed * 10**9 // calls))
def test_transferred_benchmark(cfg, workers): # Time trransferred call with multiple ongoing and completed operations. ticket = Ticket(testutil.create_ticket(ops=["read"]), cfg) ops = 10000 # Add some completed ranges - assume worst case when ranges are not # continues. for i in range(workers): ticket.run(Operation(i * 1000, 100)) # Add some ongoing operations - assume worst case when ranges are not # continues. for i in range(workers): ticket._add_operation(Operation(i * 1000 + 200, 100)) # Time transferred call - merging ongoing and completed ranges. start = time.monotonic() for i in range(ops): ticket.transferred() elapsed = time.monotonic() - start print("%d workers, %d ops, %.3f s, %.2f ops/s" % (workers, ops, elapsed, ops / elapsed))
def test_transfered_nothing(): ticket = Ticket(testutil.create_ticket(ops=["read"])) assert ticket.transferred() == 0