polyphony 0.45.5 → 0.47.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +2 -0
  3. data/.gitmodules +0 -0
  4. data/CHANGELOG.md +23 -0
  5. data/Gemfile.lock +1 -1
  6. data/README.md +3 -3
  7. data/Rakefile +1 -1
  8. data/TODO.md +21 -22
  9. data/bin/test +4 -0
  10. data/examples/core/enumerable.rb +64 -0
  11. data/examples/performance/fiber_resume.rb +43 -0
  12. data/examples/performance/fiber_transfer.rb +13 -4
  13. data/examples/performance/thread-vs-fiber/compare.rb +59 -0
  14. data/examples/performance/thread-vs-fiber/em_server.rb +33 -0
  15. data/examples/performance/thread-vs-fiber/polyphony_server.rb +10 -21
  16. data/examples/performance/thread-vs-fiber/threaded_server.rb +22 -15
  17. data/examples/performance/thread_switch.rb +44 -0
  18. data/ext/liburing/liburing.h +585 -0
  19. data/ext/liburing/liburing/README.md +4 -0
  20. data/ext/liburing/liburing/barrier.h +73 -0
  21. data/ext/liburing/liburing/compat.h +15 -0
  22. data/ext/liburing/liburing/io_uring.h +343 -0
  23. data/ext/liburing/queue.c +333 -0
  24. data/ext/liburing/register.c +187 -0
  25. data/ext/liburing/setup.c +210 -0
  26. data/ext/liburing/syscall.c +54 -0
  27. data/ext/liburing/syscall.h +18 -0
  28. data/ext/polyphony/backend.h +0 -14
  29. data/ext/polyphony/backend_common.h +129 -0
  30. data/ext/polyphony/backend_io_uring.c +995 -0
  31. data/ext/polyphony/backend_io_uring_context.c +74 -0
  32. data/ext/polyphony/backend_io_uring_context.h +53 -0
  33. data/ext/polyphony/{libev_backend.c → backend_libev.c} +304 -294
  34. data/ext/polyphony/event.c +1 -1
  35. data/ext/polyphony/extconf.rb +31 -13
  36. data/ext/polyphony/fiber.c +35 -24
  37. data/ext/polyphony/libev.c +4 -0
  38. data/ext/polyphony/libev.h +8 -2
  39. data/ext/polyphony/liburing.c +8 -0
  40. data/ext/polyphony/playground.c +51 -0
  41. data/ext/polyphony/polyphony.c +8 -5
  42. data/ext/polyphony/polyphony.h +23 -19
  43. data/ext/polyphony/polyphony_ext.c +10 -4
  44. data/ext/polyphony/queue.c +100 -35
  45. data/ext/polyphony/thread.c +10 -10
  46. data/lib/polyphony/adapters/trace.rb +2 -2
  47. data/lib/polyphony/core/exceptions.rb +0 -4
  48. data/lib/polyphony/core/global_api.rb +45 -21
  49. data/lib/polyphony/core/resource_pool.rb +12 -1
  50. data/lib/polyphony/extensions/core.rb +9 -15
  51. data/lib/polyphony/extensions/debug.rb +13 -0
  52. data/lib/polyphony/extensions/fiber.rb +8 -4
  53. data/lib/polyphony/extensions/openssl.rb +6 -0
  54. data/lib/polyphony/extensions/socket.rb +73 -10
  55. data/lib/polyphony/version.rb +1 -1
  56. data/test/helper.rb +36 -4
  57. data/test/io_uring_test.rb +55 -0
  58. data/test/stress.rb +4 -1
  59. data/test/test_backend.rb +63 -6
  60. data/test/test_ext.rb +1 -2
  61. data/test/test_fiber.rb +55 -20
  62. data/test/test_global_api.rb +107 -35
  63. data/test/test_queue.rb +117 -0
  64. data/test/test_resource_pool.rb +21 -0
  65. data/test/test_socket.rb +2 -2
  66. data/test/test_throttler.rb +3 -6
  67. data/test/test_trace.rb +7 -5
  68. metadata +28 -3
@@ -48,6 +48,27 @@ class ResourcePoolTest < MiniTest::Test
48
48
  assert_equal 1, pool.size
49
49
  end
50
50
 
51
+ def test_discard_with_block
52
+ resources = [+'a', +'b', +'c', +'d', +'e', +'f']
53
+ pool = Polyphony::ResourcePool.new(limit: 4) { resources.shift }
54
+
55
+ buffer = []
56
+ (1..4).each do |i|
57
+ spin do
58
+ 3.times do
59
+ pool.acquire { |r| buffer << [i, r]; trace [i]; snooze }
60
+ end
61
+ end
62
+ end
63
+
64
+ 2.times { trace [0]; snooze }
65
+ assert_equal [[1, 'a'], [2, 'b'], [3, 'c'], [4, 'd']], buffer
66
+
67
+ pool.discard! { |r| r == 'a' || r == 'c' }
68
+ 2.times { trace [0]; snooze }
69
+ assert_equal [[1, 'a'], [2, 'b'], [3, 'c'], [4, 'd'], [1, 'b'], [2, 'd'], [3, 'e'], [4, 'f']], buffer
70
+ end
71
+
51
72
  def test_single_resource_limit
52
73
  resources = [+'a', +'b']
53
74
  pool = Polyphony::ResourcePool.new(limit: 1) { resources.shift }
@@ -40,12 +40,12 @@ class HTTPClientTest < MiniTest::Test
40
40
  def test_http
41
41
  res = HTTParty.get('http://worldtimeapi.org/api/timezone/Europe/Paris')
42
42
  response = JSON.load(res.body)
43
- assert_equal "CEST", response['abbreviation']
43
+ assert_equal "CET", response['abbreviation']
44
44
  end
45
45
 
46
46
  def test_https
47
47
  res = HTTParty.get('https://worldtimeapi.org/api/timezone/Europe/Paris')
48
48
  response = JSON.load(res.body)
49
- assert_equal "CEST", response['abbreviation']
49
+ assert_equal "CET", response['abbreviation']
50
50
  end
51
51
  end
@@ -10,9 +10,7 @@ class ThrottlerTest < MiniTest::Test
10
10
  f = spin { loop { t.process { buffer << 1 } } }
11
11
  sleep 0.2
12
12
  f.stop
13
- elapsed = Time.now - t0
14
- expected = (elapsed * 10).to_i
15
- assert buffer.size >= expected - 1 && buffer.size <= expected + 1
13
+ assert_in_range 1..3, buffer.size
16
14
  ensure
17
15
  t.stop
18
16
  end
@@ -25,7 +23,7 @@ class ThrottlerTest < MiniTest::Test
25
23
  end
26
24
  sleep 0.25
27
25
  f.stop
28
- assert (2..6).include?(buffer.size)
26
+ assert_in_range 2..6, buffer.size
29
27
  ensure
30
28
  t.stop
31
29
  end
@@ -36,8 +34,7 @@ class ThrottlerTest < MiniTest::Test
36
34
  f = spin { loop { t.process { buffer << 1 } } }
37
35
  sleep 0.02
38
36
  f.stop
39
- assert buffer.size >= 2
40
- assert buffer.size <= 3
37
+ assert_in_range 2..3, buffer.size
41
38
  ensure
42
39
  t.stop
43
40
  end
@@ -35,7 +35,9 @@ class TraceTest < MiniTest::Test
35
35
  def test_2_fiber_trace
36
36
  records = []
37
37
  thread = Thread.current
38
- t = Polyphony::Trace.new(:fiber_all) { |r| records << r if Thread.current == thread && r[:event] =~ /^fiber_/ }
38
+ t = Polyphony::Trace.new(:fiber_all) do |r|
39
+ records << r if Thread.current == thread && r[:event] =~ /^fiber_/
40
+ end
39
41
  t.enable
40
42
  Polyphony.trace(true)
41
43
 
@@ -50,15 +52,15 @@ class TraceTest < MiniTest::Test
50
52
  [:current, :fiber_switchpoint],
51
53
  [:f, :fiber_run],
52
54
  [:f, :fiber_switchpoint],
53
- [:f, :fiber_ev_loop_enter],
55
+ [:f, :fiber_event_poll_enter],
54
56
  [:f, :fiber_schedule],
55
- [:f, :fiber_ev_loop_leave],
57
+ [:f, :fiber_event_poll_leave],
56
58
  [:f, :fiber_run],
57
59
  [:f, :fiber_terminate],
58
60
  [:current, :fiber_switchpoint],
59
- [:current, :fiber_ev_loop_enter],
61
+ [:current, :fiber_event_poll_enter],
60
62
  [:current, :fiber_schedule],
61
- [:current, :fiber_ev_loop_leave],
63
+ [:current, :fiber_event_poll_leave],
62
64
  [:current, :fiber_run]
63
65
  ], events
64
66
  ensure
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polyphony
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.45.5
4
+ version: 0.47.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sharon Rosner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-04 00:00:00.000000000 Z
11
+ date: 2020-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -278,6 +278,7 @@ extra_rdoc_files:
278
278
  files:
279
279
  - ".github/workflows/test.yml"
280
280
  - ".gitignore"
281
+ - ".gitmodules"
281
282
  - ".rubocop.yml"
282
283
  - ".vscode/launch.json"
283
284
  - CHANGELOG.md
@@ -289,6 +290,7 @@ files:
289
290
  - TODO.md
290
291
  - bin/polyphony-debug
291
292
  - bin/stress.rb
293
+ - bin/test
292
294
  - docs/_config.yml
293
295
  - docs/_includes/head.html
294
296
  - docs/_includes/title.html
@@ -346,6 +348,7 @@ files:
346
348
  - examples/core/await.rb
347
349
  - examples/core/channels.rb
348
350
  - examples/core/deferring-an-operation.rb
351
+ - examples/core/enumerable.rb
349
352
  - examples/core/erlang-style-genserver.rb
350
353
  - examples/core/forking.rb
351
354
  - examples/core/handling-signals.rb
@@ -384,6 +387,7 @@ files:
384
387
  - examples/io/tcpsocket.rb
385
388
  - examples/io/tunnel.rb
386
389
  - examples/io/zip.rb
390
+ - examples/performance/fiber_resume.rb
387
391
  - examples/performance/fiber_transfer.rb
388
392
  - examples/performance/fs_read.rb
389
393
  - examples/performance/mem-usage.rb
@@ -392,6 +396,8 @@ files:
392
396
  - examples/performance/snooze.rb
393
397
  - examples/performance/snooze_raw.rb
394
398
  - examples/performance/switch.rb
399
+ - examples/performance/thread-vs-fiber/compare.rb
400
+ - examples/performance/thread-vs-fiber/em_server.rb
395
401
  - examples/performance/thread-vs-fiber/httparty_multi.rb
396
402
  - examples/performance/thread-vs-fiber/httparty_threaded.rb
397
403
  - examples/performance/thread-vs-fiber/polyphony_mt_server.rb
@@ -399,6 +405,7 @@ files:
399
405
  - examples/performance/thread-vs-fiber/polyphony_server_read_loop.rb
400
406
  - examples/performance/thread-vs-fiber/threaded_server.rb
401
407
  - examples/performance/thread_pool_perf.rb
408
+ - examples/performance/thread_switch.rb
402
409
  - ext/libev/Changes
403
410
  - ext/libev/LICENSE
404
411
  - ext/libev/README
@@ -415,13 +422,29 @@ files:
415
422
  - ext/libev/ev_win32.c
416
423
  - ext/libev/ev_wrap.h
417
424
  - ext/libev/test_libev_win32.c
425
+ - ext/liburing/liburing.h
426
+ - ext/liburing/liburing/README.md
427
+ - ext/liburing/liburing/barrier.h
428
+ - ext/liburing/liburing/compat.h
429
+ - ext/liburing/liburing/io_uring.h
430
+ - ext/liburing/queue.c
431
+ - ext/liburing/register.c
432
+ - ext/liburing/setup.c
433
+ - ext/liburing/syscall.c
434
+ - ext/liburing/syscall.h
418
435
  - ext/polyphony/backend.h
436
+ - ext/polyphony/backend_common.h
437
+ - ext/polyphony/backend_io_uring.c
438
+ - ext/polyphony/backend_io_uring_context.c
439
+ - ext/polyphony/backend_io_uring_context.h
440
+ - ext/polyphony/backend_libev.c
419
441
  - ext/polyphony/event.c
420
442
  - ext/polyphony/extconf.rb
421
443
  - ext/polyphony/fiber.c
422
444
  - ext/polyphony/libev.c
423
445
  - ext/polyphony/libev.h
424
- - ext/polyphony/libev_backend.c
446
+ - ext/polyphony/liburing.c
447
+ - ext/polyphony/playground.c
425
448
  - ext/polyphony/polyphony.c
426
449
  - ext/polyphony/polyphony.h
427
450
  - ext/polyphony/polyphony_ext.c
@@ -451,6 +474,7 @@ files:
451
474
  - lib/polyphony/core/thread_pool.rb
452
475
  - lib/polyphony/core/throttler.rb
453
476
  - lib/polyphony/extensions/core.rb
477
+ - lib/polyphony/extensions/debug.rb
454
478
  - lib/polyphony/extensions/fiber.rb
455
479
  - lib/polyphony/extensions/io.rb
456
480
  - lib/polyphony/extensions/openssl.rb
@@ -462,6 +486,7 @@ files:
462
486
  - test/coverage.rb
463
487
  - test/eg.rb
464
488
  - test/helper.rb
489
+ - test/io_uring_test.rb
465
490
  - test/q.rb
466
491
  - test/run.rb
467
492
  - test/stress.rb