spawn.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import contextlib
  2. import eventlet
  3. import benchmarks
  4. def dummy(i=None):
  5. return i
  6. def linked(gt, arg):
  7. return arg
  8. def benchmark_sleep():
  9. eventlet.sleep()
  10. def benchmark_spawn_link1():
  11. t = eventlet.spawn(dummy)
  12. t.link(linked, 1)
  13. t.wait()
  14. def benchmark_spawn_link5():
  15. t = eventlet.spawn(dummy)
  16. t.link(linked, 1)
  17. t.link(linked, 2)
  18. t.link(linked, 3)
  19. t.link(linked, 4)
  20. t.link(linked, 5)
  21. t.wait()
  22. def benchmark_spawn_link5_unlink3():
  23. t = eventlet.spawn(dummy)
  24. t.link(linked, 1)
  25. t.link(linked, 2)
  26. t.link(linked, 3)
  27. t.link(linked, 4)
  28. t.link(linked, 5)
  29. t.unlink(linked, 3)
  30. t.wait()
  31. @benchmarks.configure(max_iters=1e5)
  32. def benchmark_spawn_nowait():
  33. eventlet.spawn(dummy, 1)
  34. def benchmark_spawn():
  35. eventlet.spawn(dummy, 1).wait()
  36. @benchmarks.configure(max_iters=1e5)
  37. def benchmark_spawn_n():
  38. eventlet.spawn_n(dummy, 1)
  39. @benchmarks.configure(max_iters=1e5)
  40. def benchmark_spawn_n_kw():
  41. eventlet.spawn_n(dummy, i=1)
  42. @contextlib.contextmanager
  43. def pool_setup(iters):
  44. pool = eventlet.GreenPool(iters)
  45. yield pool
  46. pool.waitall()
  47. @benchmarks.configure(manager=pool_setup)
  48. def benchmark_pool_spawn(pool):
  49. pool.spawn(dummy, 1)
  50. @benchmarks.configure(manager=pool_setup, max_iters=1e5)
  51. def benchmark_pool_spawn_n(pool):
  52. pool.spawn_n(dummy, 1)