polyphony 0.45.5 → 0.46.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +2 -0
  3. data/.gitmodules +0 -0
  4. data/CHANGELOG.md +4 -0
  5. data/Gemfile.lock +1 -1
  6. data/README.md +3 -3
  7. data/Rakefile +1 -1
  8. data/TODO.md +4 -4
  9. data/examples/performance/thread-vs-fiber/polyphony_server.rb +1 -2
  10. data/ext/liburing/liburing.h +585 -0
  11. data/ext/liburing/liburing/README.md +4 -0
  12. data/ext/liburing/liburing/barrier.h +73 -0
  13. data/ext/liburing/liburing/compat.h +15 -0
  14. data/ext/liburing/liburing/io_uring.h +343 -0
  15. data/ext/liburing/queue.c +333 -0
  16. data/ext/liburing/register.c +187 -0
  17. data/ext/liburing/setup.c +210 -0
  18. data/ext/liburing/syscall.c +54 -0
  19. data/ext/liburing/syscall.h +18 -0
  20. data/ext/polyphony/backend.h +0 -14
  21. data/ext/polyphony/backend_common.h +109 -0
  22. data/ext/polyphony/backend_io_uring.c +884 -0
  23. data/ext/polyphony/backend_io_uring_context.c +73 -0
  24. data/ext/polyphony/backend_io_uring_context.h +52 -0
  25. data/ext/polyphony/{libev_backend.c → backend_libev.c} +202 -294
  26. data/ext/polyphony/event.c +1 -1
  27. data/ext/polyphony/extconf.rb +31 -13
  28. data/ext/polyphony/fiber.c +29 -22
  29. data/ext/polyphony/libev.c +4 -0
  30. data/ext/polyphony/libev.h +8 -2
  31. data/ext/polyphony/liburing.c +8 -0
  32. data/ext/polyphony/playground.c +51 -0
  33. data/ext/polyphony/polyphony.c +5 -5
  34. data/ext/polyphony/polyphony.h +16 -12
  35. data/ext/polyphony/polyphony_ext.c +10 -4
  36. data/ext/polyphony/queue.c +1 -1
  37. data/ext/polyphony/thread.c +11 -9
  38. data/lib/polyphony/adapters/trace.rb +2 -2
  39. data/lib/polyphony/core/global_api.rb +1 -4
  40. data/lib/polyphony/extensions/debug.rb +13 -0
  41. data/lib/polyphony/extensions/fiber.rb +2 -2
  42. data/lib/polyphony/extensions/socket.rb +59 -10
  43. data/lib/polyphony/version.rb +1 -1
  44. data/test/helper.rb +36 -4
  45. data/test/io_uring_test.rb +55 -0
  46. data/test/stress.rb +5 -2
  47. data/test/test_backend.rb +4 -6
  48. data/test/test_ext.rb +1 -2
  49. data/test/test_fiber.rb +22 -16
  50. data/test/test_global_api.rb +33 -35
  51. data/test/test_throttler.rb +3 -6
  52. data/test/test_trace.rb +7 -5
  53. metadata +22 -3
@@ -72,28 +72,32 @@ class ExceptionTest < MiniTest::Test
72
72
  rescue Exception => e
73
73
  frames << 3
74
74
  raise e
75
- end#.await
76
- 5.times { snooze }
77
- rescue Exception => e
78
- error = e
79
- ensure
80
- assert_kind_of RuntimeError, error
81
- assert_equal [2, 3], frames
75
+ end
76
+ begin
77
+ 5.times { snooze }
78
+ rescue Exception => e
79
+ error = e
80
+ ensure
81
+ assert_kind_of RuntimeError, error
82
+ assert_equal [2, 3], frames
83
+ end
82
84
  end
83
85
 
84
86
  def test_cross_fiber_backtrace_with_dead_calling_fiber
85
87
  error = nil
86
- spin do
88
+ begin
87
89
  spin do
88
90
  spin do
89
- raise 'foo'
91
+ spin do
92
+ raise 'foo'
93
+ end.await
90
94
  end.await
91
95
  end.await
92
- end.await
93
- rescue Exception => e
94
- error = e
95
- ensure
96
- assert_kind_of RuntimeError, error
96
+ rescue Exception => e
97
+ error = e
98
+ ensure
99
+ assert_kind_of RuntimeError, error
100
+ end
97
101
  end
98
102
  end
99
103
 
@@ -133,8 +137,7 @@ class MoveOnAfterTest < MiniTest::Test
133
137
  t1 = Time.now
134
138
 
135
139
  assert_nil v
136
- assert t1 - t0 >= 0.014
137
- assert t1 - t0 < 0.02
140
+ assert_in_range 0.014..0.02, t1 - t0
138
141
  end
139
142
 
140
143
  def test_move_on_after_without_block
@@ -185,8 +188,7 @@ class CancelAfterTest < MiniTest::Test
185
188
  sleep 0.007
186
189
  end
187
190
  t1 = Time.now
188
- assert t1 - t0 >= 0.014
189
- assert t1 - t0 < 0.02
191
+ assert_in_range 0.014..0.02, t1 - t0
190
192
  end
191
193
 
192
194
  class CustomException < Exception
@@ -255,12 +257,10 @@ class SpinLoopTest < MiniTest::Test
255
257
  buffer = []
256
258
  counter = 0
257
259
  t0 = Time.now
258
- f = spin_loop(rate: 10) { buffer << (counter += 1) }
259
- sleep 0.2
260
+ f = spin_loop(rate: 100) { buffer << (counter += 1) }
261
+ sleep 0.02
260
262
  f.stop
261
- elapsed = Time.now - t0
262
- expected = (elapsed * 10).to_i
263
- assert counter >= expected - 1 && counter <= expected + 1
263
+ assert_in_range 1..3, counter
264
264
  end
265
265
  end
266
266
 
@@ -270,22 +270,22 @@ class ThrottledLoopTest < MiniTest::Test
270
270
  counter = 0
271
271
  t0 = Time.now
272
272
  f = spin do
273
- throttled_loop(10) { buffer << (counter += 1) }
273
+ throttled_loop(100) { buffer << (counter += 1) }
274
274
  end
275
- sleep 0.3
276
- f.stop
277
- elapsed = Time.now - t0
278
- expected = (elapsed * 10).to_i
279
- assert counter >= expected - 1 && counter <= expected + 1
275
+ sleep 0.03
276
+ assert_in_range 2..4, counter
280
277
  end
281
278
 
282
279
  def test_throttled_loop_with_count
283
280
  buffer = []
284
281
  counter = 0
282
+ t0 = Time.now
285
283
  f = spin do
286
284
  throttled_loop(50, count: 5) { buffer << (counter += 1) }
287
285
  end
288
286
  f.await
287
+ t1 = Time.now
288
+ assert_in_range 0.075..0.15, t1 - t0
289
289
  assert_equal [1, 2, 3, 4, 5], buffer
290
290
  end
291
291
  end
@@ -304,13 +304,11 @@ class GlobalAPIEtcTest < MiniTest::Test
304
304
  buffer = []
305
305
  t0 = Time.now
306
306
  f = spin do
307
- every(0.1) { buffer << 1 }
307
+ every(0.01) { buffer << 1 }
308
308
  end
309
- sleep 0.5
309
+ sleep 0.05
310
310
  f.stop
311
- elapsed = Time.now - t0
312
- expected = (elapsed / 0.1).to_i
313
- assert buffer.size >= expected - 2 && buffer.size <= expected + 2
311
+ assert_in_range 4..6, buffer.size
314
312
  end
315
313
 
316
314
  def test_sleep
@@ -378,4 +376,4 @@ class GlobalAPIEtcTest < MiniTest::Test
378
376
 
379
377
  assert_equal [0, 1, 2], values
380
378
  end
381
- end
379
+ 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.46.0
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-10-08 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
@@ -415,13 +416,29 @@ files:
415
416
  - ext/libev/ev_win32.c
416
417
  - ext/libev/ev_wrap.h
417
418
  - ext/libev/test_libev_win32.c
419
+ - ext/liburing/liburing.h
420
+ - ext/liburing/liburing/README.md
421
+ - ext/liburing/liburing/barrier.h
422
+ - ext/liburing/liburing/compat.h
423
+ - ext/liburing/liburing/io_uring.h
424
+ - ext/liburing/queue.c
425
+ - ext/liburing/register.c
426
+ - ext/liburing/setup.c
427
+ - ext/liburing/syscall.c
428
+ - ext/liburing/syscall.h
418
429
  - ext/polyphony/backend.h
430
+ - ext/polyphony/backend_common.h
431
+ - ext/polyphony/backend_io_uring.c
432
+ - ext/polyphony/backend_io_uring_context.c
433
+ - ext/polyphony/backend_io_uring_context.h
434
+ - ext/polyphony/backend_libev.c
419
435
  - ext/polyphony/event.c
420
436
  - ext/polyphony/extconf.rb
421
437
  - ext/polyphony/fiber.c
422
438
  - ext/polyphony/libev.c
423
439
  - ext/polyphony/libev.h
424
- - ext/polyphony/libev_backend.c
440
+ - ext/polyphony/liburing.c
441
+ - ext/polyphony/playground.c
425
442
  - ext/polyphony/polyphony.c
426
443
  - ext/polyphony/polyphony.h
427
444
  - ext/polyphony/polyphony_ext.c
@@ -451,6 +468,7 @@ files:
451
468
  - lib/polyphony/core/thread_pool.rb
452
469
  - lib/polyphony/core/throttler.rb
453
470
  - lib/polyphony/extensions/core.rb
471
+ - lib/polyphony/extensions/debug.rb
454
472
  - lib/polyphony/extensions/fiber.rb
455
473
  - lib/polyphony/extensions/io.rb
456
474
  - lib/polyphony/extensions/openssl.rb
@@ -462,6 +480,7 @@ files:
462
480
  - test/coverage.rb
463
481
  - test/eg.rb
464
482
  - test/helper.rb
483
+ - test/io_uring_test.rb
465
484
  - test/q.rb
466
485
  - test/run.rb
467
486
  - test/stress.rb