| 345 | |
| 346 | |
| 347 | def 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 | |
| 373 | def queue_example(db): |