polyphony 0.40 → 0.41
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +11 -2
- data/.gitignore +2 -2
- data/.rubocop.yml +30 -0
- data/CHANGELOG.md +6 -2
- data/Gemfile.lock +9 -6
- data/Rakefile +2 -2
- data/TODO.md +18 -97
- data/docs/_includes/head.html +40 -0
- data/docs/_includes/nav.html +5 -5
- data/docs/api-reference/fiber.md +2 -2
- data/docs/main-concepts/design-principles.md +67 -9
- data/docs/main-concepts/extending.md +1 -1
- data/examples/core/xx-agent.rb +102 -0
- data/examples/core/xx-sleeping.rb +14 -6
- data/examples/io/xx-irb.rb +1 -1
- data/examples/performance/thread-vs-fiber/polyphony_mt_server.rb +7 -6
- data/examples/performance/thread-vs-fiber/polyphony_server.rb +14 -25
- data/ext/{gyro → polyphony}/extconf.rb +2 -2
- data/ext/{gyro → polyphony}/fiber.c +15 -19
- data/ext/{gyro → polyphony}/libev.c +0 -0
- data/ext/{gyro → polyphony}/libev.h +0 -0
- data/ext/polyphony/libev_agent.c +503 -0
- data/ext/polyphony/libev_queue.c +214 -0
- data/ext/{gyro/gyro.c → polyphony/polyphony.c} +16 -25
- data/ext/polyphony/polyphony.h +90 -0
- data/ext/polyphony/polyphony_ext.c +23 -0
- data/ext/{gyro → polyphony}/socket.c +14 -14
- data/ext/{gyro → polyphony}/thread.c +32 -115
- data/ext/{gyro → polyphony}/tracing.c +1 -1
- data/lib/polyphony.rb +16 -12
- data/lib/polyphony/adapters/irb.rb +1 -1
- data/lib/polyphony/adapters/postgres.rb +6 -5
- data/lib/polyphony/adapters/process.rb +5 -5
- data/lib/polyphony/adapters/trace.rb +28 -28
- data/lib/polyphony/core/channel.rb +3 -3
- data/lib/polyphony/core/exceptions.rb +1 -1
- data/lib/polyphony/core/global_api.rb +11 -9
- data/lib/polyphony/core/resource_pool.rb +3 -3
- data/lib/polyphony/core/sync.rb +2 -2
- data/lib/polyphony/core/thread_pool.rb +6 -6
- data/lib/polyphony/core/throttler.rb +13 -6
- data/lib/polyphony/event.rb +27 -0
- data/lib/polyphony/extensions/core.rb +20 -11
- data/lib/polyphony/extensions/fiber.rb +4 -4
- data/lib/polyphony/extensions/io.rb +56 -26
- data/lib/polyphony/extensions/openssl.rb +4 -8
- data/lib/polyphony/extensions/socket.rb +27 -9
- data/lib/polyphony/extensions/thread.rb +16 -9
- data/lib/polyphony/net.rb +9 -9
- data/lib/polyphony/version.rb +1 -1
- data/polyphony.gemspec +2 -2
- data/test/helper.rb +12 -1
- data/test/test_agent.rb +77 -0
- data/test/{test_async.rb → test_event.rb} +13 -7
- data/test/test_ext.rb +25 -4
- data/test/test_fiber.rb +19 -10
- data/test/test_global_api.rb +4 -4
- data/test/test_io.rb +46 -24
- data/test/test_queue.rb +74 -0
- data/test/test_signal.rb +3 -40
- data/test/test_socket.rb +33 -0
- data/test/test_thread.rb +37 -16
- data/test/test_trace.rb +6 -5
- metadata +24 -24
- data/ext/gyro/async.c +0 -132
- data/ext/gyro/child.c +0 -108
- data/ext/gyro/gyro.h +0 -158
- data/ext/gyro/gyro_ext.c +0 -33
- data/ext/gyro/io.c +0 -457
- data/ext/gyro/queue.c +0 -146
- data/ext/gyro/selector.c +0 -205
- data/ext/gyro/signal.c +0 -99
- data/ext/gyro/timer.c +0 -115
- data/test/test_timer.rb +0 -56
data/ext/gyro/timer.c
DELETED
@@ -1,115 +0,0 @@
|
|
1
|
-
#include "gyro.h"
|
2
|
-
|
3
|
-
struct Gyro_Timer {
|
4
|
-
GYRO_WATCHER_DECL(ev_timer);
|
5
|
-
double after;
|
6
|
-
double repeat;
|
7
|
-
};
|
8
|
-
|
9
|
-
VALUE cGyro_Timer = Qnil;
|
10
|
-
|
11
|
-
static void Gyro_Timer_mark(void *ptr) {
|
12
|
-
struct Gyro_Timer *timer = ptr;
|
13
|
-
GYRO_WATCHER_MARK(timer);
|
14
|
-
}
|
15
|
-
|
16
|
-
static void Gyro_Timer_free(void *ptr) {
|
17
|
-
struct Gyro_Timer *timer = ptr;
|
18
|
-
GYRO_WATCHER_FREE(timer);
|
19
|
-
}
|
20
|
-
|
21
|
-
static size_t Gyro_Timer_size(const void *ptr) {
|
22
|
-
return sizeof(struct Gyro_Timer);
|
23
|
-
}
|
24
|
-
|
25
|
-
static const rb_data_type_t Gyro_Timer_type = {
|
26
|
-
"Gyro_Timer",
|
27
|
-
{Gyro_Timer_mark, Gyro_Timer_free, Gyro_Timer_size,},
|
28
|
-
0, 0, 0
|
29
|
-
};
|
30
|
-
|
31
|
-
static VALUE Gyro_Timer_allocate(VALUE klass) {
|
32
|
-
struct Gyro_Timer *timer = ALLOC(struct Gyro_Timer);
|
33
|
-
return TypedData_Wrap_Struct(klass, &Gyro_Timer_type, timer);
|
34
|
-
}
|
35
|
-
|
36
|
-
#define GetGyro_Timer(obj, timer) \
|
37
|
-
TypedData_Get_Struct((obj), struct Gyro_Timer, &Gyro_Timer_type, (timer))
|
38
|
-
|
39
|
-
inline void timer_activate(struct Gyro_Timer *timer) {
|
40
|
-
timer->fiber = rb_fiber_current();
|
41
|
-
timer->selector = Thread_current_event_selector();
|
42
|
-
timer->ev_loop = Gyro_Selector_ev_loop(timer->selector);
|
43
|
-
|
44
|
-
if (timer->active) return;
|
45
|
-
|
46
|
-
timer->active = 1;
|
47
|
-
Gyro_Selector_add_active_watcher(timer->selector, timer->self);
|
48
|
-
ev_timer_start(timer->ev_loop, &timer->ev_timer);
|
49
|
-
}
|
50
|
-
|
51
|
-
inline void timer_deactivate(struct Gyro_Timer *timer, int non_recurring_only) {
|
52
|
-
if (!timer->active) return;
|
53
|
-
|
54
|
-
if (!timer->repeat || !non_recurring_only) {
|
55
|
-
ev_timer_stop(timer->ev_loop, &timer->ev_timer);
|
56
|
-
if (RTEST(timer->selector)) {
|
57
|
-
Gyro_Selector_remove_active_watcher(timer->selector, timer->self);
|
58
|
-
timer->selector = Qnil;
|
59
|
-
}
|
60
|
-
timer->ev_loop = 0;
|
61
|
-
timer->active = 0;
|
62
|
-
}
|
63
|
-
|
64
|
-
timer->fiber = Qnil;
|
65
|
-
}
|
66
|
-
|
67
|
-
void Gyro_Timer_callback(struct ev_loop *ev_loop, struct ev_timer *ev_timer, int revents) {
|
68
|
-
struct Gyro_Timer *timer = (struct Gyro_Timer*)ev_timer;
|
69
|
-
|
70
|
-
Fiber_make_runnable(timer->fiber, DBL2NUM(timer->after));
|
71
|
-
timer_deactivate(timer, 1);
|
72
|
-
}
|
73
|
-
|
74
|
-
static VALUE Gyro_Timer_initialize(VALUE self, VALUE after, VALUE repeat) {
|
75
|
-
struct Gyro_Timer *timer;
|
76
|
-
|
77
|
-
GetGyro_Timer(self, timer);
|
78
|
-
GYRO_WATCHER_INITIALIZE(timer, self);
|
79
|
-
timer->after = NUM2DBL(after);
|
80
|
-
timer->repeat = NUM2DBL(repeat);
|
81
|
-
ev_timer_init(&timer->ev_timer, Gyro_Timer_callback, timer->after, timer->repeat);
|
82
|
-
|
83
|
-
return Qnil;
|
84
|
-
}
|
85
|
-
|
86
|
-
VALUE Gyro_Timer_stop(VALUE self) {
|
87
|
-
struct Gyro_Timer *timer;
|
88
|
-
GetGyro_Timer(self, timer);
|
89
|
-
|
90
|
-
timer_deactivate(timer, 0);
|
91
|
-
return self;
|
92
|
-
}
|
93
|
-
|
94
|
-
VALUE Gyro_Timer_await(VALUE self) {
|
95
|
-
struct Gyro_Timer *timer;
|
96
|
-
VALUE ret;
|
97
|
-
GetGyro_Timer(self, timer);
|
98
|
-
|
99
|
-
timer_activate(timer);
|
100
|
-
ret = Gyro_switchpoint();
|
101
|
-
timer_deactivate(timer, 1);
|
102
|
-
|
103
|
-
TEST_RESUME_EXCEPTION(ret);
|
104
|
-
RB_GC_GUARD(ret);
|
105
|
-
return ret;
|
106
|
-
}
|
107
|
-
|
108
|
-
void Init_Gyro_Timer() {
|
109
|
-
cGyro_Timer = rb_define_class_under(mGyro, "Timer", rb_cData);
|
110
|
-
rb_define_alloc_func(cGyro_Timer, Gyro_Timer_allocate);
|
111
|
-
|
112
|
-
rb_define_method(cGyro_Timer, "initialize", Gyro_Timer_initialize, 2);
|
113
|
-
rb_define_method(cGyro_Timer, "await", Gyro_Timer_await, 0);
|
114
|
-
rb_define_method(cGyro_Timer, "stop", Gyro_Timer_stop, 0);
|
115
|
-
}
|
data/test/test_timer.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'helper'
|
4
|
-
|
5
|
-
class TimerTest < MiniTest::Test
|
6
|
-
def test_that_one_shot_timer_works
|
7
|
-
count = 0
|
8
|
-
t = Gyro::Timer.new(0.01, 0)
|
9
|
-
spin {
|
10
|
-
t.await
|
11
|
-
count += 1
|
12
|
-
}
|
13
|
-
suspend
|
14
|
-
assert_equal 1, count
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_that_repeating_timer_works
|
18
|
-
count = 0
|
19
|
-
t = Gyro::Timer.new(0.001, 0.001)
|
20
|
-
spin {
|
21
|
-
loop {
|
22
|
-
t.await
|
23
|
-
count += 1
|
24
|
-
break if count >= 3
|
25
|
-
}
|
26
|
-
}
|
27
|
-
suspend
|
28
|
-
assert_equal 3, count
|
29
|
-
ensure
|
30
|
-
t.stop
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_that_repeating_timer_compensates_for_drift
|
34
|
-
count = 0
|
35
|
-
t = Gyro::Timer.new(0.1, 0.1)
|
36
|
-
deltas = []
|
37
|
-
last = nil
|
38
|
-
spin {
|
39
|
-
last = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
|
40
|
-
loop {
|
41
|
-
t.await
|
42
|
-
now = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
|
43
|
-
elapsed = (now - last)
|
44
|
-
deltas << elapsed
|
45
|
-
last = now
|
46
|
-
count += 1
|
47
|
-
sleep 0.05
|
48
|
-
break if count >= 3
|
49
|
-
}
|
50
|
-
}
|
51
|
-
suspend
|
52
|
-
assert_equal 0, deltas[1..-1].filter { |d| (d - 0.1).abs >= 0.05 }.size
|
53
|
-
ensure
|
54
|
-
t.stop
|
55
|
-
end
|
56
|
-
end
|