MCPcopy Create free account
hub / github.com/apple/foundationdb / queue_multi_client_example

Function queue_multi_client_example

layers/containers/highcontention/queue.py:347–370  ·  view source on GitHub ↗
(db)

Source from the content-addressed store, hash-verified

345
346
347def queue_multi_client_example(db):
348 descriptions = ["simple queue", "high contention queue"]
349
350 for highContention in range(2):
351 print 'Starting %s test' % descriptions[highContention]
352 queue = Queue(Subspace(('queue_example',)), highContention > 0)
353 queue.clear(db)
354
355 pushThreads = [threading.Thread(target=push_thread, args=(queue, db, i, 100)) for i in range(10)]
356 popThreads = [threading.Thread(target=pop_thread, args=(queue, db, i, 100)) for i in range(10)]
357
358 start = time.time()
359
360 for push in pushThreads:
361 push.start()
362 for pop in popThreads:
363 pop.start()
364 for push in pushThreads:
365 push.join()
366 for pop in popThreads:
367 pop.join()
368
369 end = time.time()
370 print 'Finished %s in %f seconds' % (descriptions[highContention], end - start)
371
372
373def queue_example(db):

Callers 1

queue_exampleFunction · 0.85

Calls 8

clearMethod · 0.95
rangeFunction · 0.85
ThreadMethod · 0.80
QueueClass · 0.70
SubspaceClass · 0.70
timeMethod · 0.65
startMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected