polyphony 0.73.1 → 0.74
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.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +13 -10
- data/.github/workflows/test_io_uring.yml +32 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +10 -7
- data/bin/pdbg +0 -0
- data/bin/polyphony-debug +0 -0
- data/bin/stress.rb +0 -0
- data/bin/test +0 -0
- data/ext/polyphony/backend_common.c +75 -11
- data/ext/polyphony/backend_common.h +7 -0
- data/ext/polyphony/backend_io_uring.c +226 -106
- data/ext/polyphony/backend_io_uring_context.c +1 -0
- data/ext/polyphony/backend_io_uring_context.h +2 -1
- data/ext/polyphony/backend_libev.c +7 -9
- data/ext/polyphony/event.c +5 -2
- data/ext/polyphony/polyphony.c +10 -1
- data/ext/polyphony/polyphony.h +2 -0
- data/ext/polyphony/queue.c +10 -5
- data/ext/polyphony/runqueue_ring_buffer.c +3 -1
- data/ext/polyphony/socket_extensions.c +5 -2
- data/lib/polyphony/extensions/fiber.rb +58 -0
- data/lib/polyphony/extensions/socket.rb +17 -5
- data/lib/polyphony/extensions/thread.rb +9 -3
- data/lib/polyphony/version.rb +1 -1
- data/lib/polyphony.rb +2 -1
- data/test/test_backend.rb +3 -5
- data/test/test_global_api.rb +10 -14
- data/test/test_io.rb +2 -2
- data/test/test_kernel.rb +2 -2
- data/test/test_socket.rb +35 -2
- data/test/test_thread_pool.rb +1 -1
- data/test/test_throttler.rb +3 -3
- data/test/test_timer.rb +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2948e34f11b2bcb60406fda1024cac8d93c9019edfc97a8febe083d503b56d88
|
4
|
+
data.tar.gz: 4bedbe795bbdb669123da5d4d671e78e6cfe3a021ddf13f2a80563a80ca92571
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36cf3fecb1b3ad6dc7aec6a5a12b2a0db5e7e4f2fc15a201c5e6dbe692a3ebcf5d62bc8aad8febfb224c393014c40090245c47c93dec8b41bd9732b6002c9a8f
|
7
|
+
data.tar.gz: 8ad3f84d0af1eb5bb1535eb53128fb4f0602491e673128a873c8ef5176735ed61c6e1c53eb0b5faeb0792e299e771321a204f42d588566274f1737f16281a09e
|
data/.github/workflows/test.yml
CHANGED
@@ -7,26 +7,29 @@ jobs:
|
|
7
7
|
strategy:
|
8
8
|
fail-fast: false
|
9
9
|
matrix:
|
10
|
-
os: [ubuntu-latest,
|
11
|
-
ruby: [2.
|
10
|
+
os: [ubuntu-latest, macos-latest]
|
11
|
+
ruby: ['2.7', '3.0', '3.1', 'head']
|
12
12
|
|
13
13
|
name: >-
|
14
14
|
${{matrix.os}}, ${{matrix.ruby}}
|
15
15
|
|
16
16
|
runs-on: ${{matrix.os}}
|
17
|
+
|
18
|
+
env:
|
19
|
+
POLYPHONY_USE_LIBEV: "1"
|
20
|
+
|
17
21
|
steps:
|
18
|
-
-
|
19
|
-
|
22
|
+
- name: Setup OS
|
23
|
+
uses: actions/checkout@v1
|
24
|
+
- name: Setup Ruby
|
25
|
+
uses: ruby/setup-ruby@v1
|
20
26
|
with:
|
21
27
|
ruby-version: ${{matrix.ruby}}
|
22
28
|
bundler-cache: true # 'bundle install' and cache
|
23
|
-
|
24
|
-
|
25
|
-
gem install bundler
|
26
|
-
bundle install
|
27
|
-
- name: Show Linux kernel version
|
29
|
+
cache-version: 2
|
30
|
+
- name: Kernel version
|
28
31
|
run: uname -a
|
29
32
|
- name: Compile C-extension
|
30
|
-
run:
|
33
|
+
run: bundle exec rake compile
|
31
34
|
- name: Run tests
|
32
35
|
run: bundle exec rake test
|
@@ -0,0 +1,32 @@
|
|
1
|
+
name: Tests with io_uring
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
strategy:
|
8
|
+
fail-fast: false
|
9
|
+
matrix:
|
10
|
+
os: [ubuntu-latest]
|
11
|
+
ruby: [2.6, 2.7, 3.0]
|
12
|
+
|
13
|
+
name: >-
|
14
|
+
${{matrix.os}}, ${{matrix.ruby}}
|
15
|
+
|
16
|
+
runs-on: ${{matrix.os}}
|
17
|
+
steps:
|
18
|
+
- uses: actions/checkout@v1
|
19
|
+
- uses: ruby/setup-ruby@v1
|
20
|
+
with:
|
21
|
+
ruby-version: ${{matrix.ruby}}
|
22
|
+
bundler-cache: true # 'bundle install' and cache
|
23
|
+
- name: Install dependencies
|
24
|
+
run: |
|
25
|
+
gem install bundler
|
26
|
+
bundle install
|
27
|
+
- name: Show Linux kernel version
|
28
|
+
run: uname -a
|
29
|
+
- name: Compile C-extension
|
30
|
+
run: bundle exec rake compile
|
31
|
+
- name: Run tests
|
32
|
+
run: bundle exec rake test
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
polyphony (0.
|
4
|
+
polyphony (0.74)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -19,7 +19,7 @@ GEM
|
|
19
19
|
method_source (1.0.0)
|
20
20
|
mime-types (3.4.1)
|
21
21
|
mime-types-data (~> 3.2015)
|
22
|
-
mime-types-data (3.
|
22
|
+
mime-types-data (3.2022.0105)
|
23
23
|
minitest (5.14.4)
|
24
24
|
minitest-reporters (1.4.2)
|
25
25
|
ansi
|
@@ -29,12 +29,12 @@ GEM
|
|
29
29
|
msgpack (1.4.2)
|
30
30
|
multi_xml (0.6.0)
|
31
31
|
parallel (1.21.0)
|
32
|
-
parser (3.0.
|
32
|
+
parser (3.1.0.0)
|
33
33
|
ast (~> 2.4.1)
|
34
34
|
pry (0.13.1)
|
35
35
|
coderay (~> 1.1)
|
36
36
|
method_source (~> 1.0)
|
37
|
-
rainbow (3.
|
37
|
+
rainbow (3.1.1)
|
38
38
|
rake (13.0.6)
|
39
39
|
rake-compiler (1.1.1)
|
40
40
|
rake
|
@@ -49,7 +49,7 @@ GEM
|
|
49
49
|
rubocop-ast (>= 0.0.3)
|
50
50
|
ruby-progressbar (~> 1.7)
|
51
51
|
unicode-display_width (>= 1.4.0, < 2.0)
|
52
|
-
rubocop-ast (1.15.
|
52
|
+
rubocop-ast (1.15.1)
|
53
53
|
parser (>= 3.0.1.1)
|
54
54
|
ruby-progressbar (1.11.0)
|
55
55
|
simplecov (0.17.1)
|
@@ -60,7 +60,10 @@ GEM
|
|
60
60
|
unicode-display_width (1.8.0)
|
61
61
|
|
62
62
|
PLATFORMS
|
63
|
-
|
63
|
+
universal-darwin
|
64
|
+
universal-freebsd
|
65
|
+
universal-linux
|
66
|
+
universal-unknown
|
64
67
|
|
65
68
|
DEPENDENCIES
|
66
69
|
httparty (= 0.17.1)
|
@@ -75,4 +78,4 @@ DEPENDENCIES
|
|
75
78
|
simplecov (= 0.17.1)
|
76
79
|
|
77
80
|
BUNDLED WITH
|
78
|
-
2.
|
81
|
+
2.3.3
|
data/bin/pdbg
CHANGED
File without changes
|
data/bin/polyphony-debug
CHANGED
File without changes
|
data/bin/stress.rb
CHANGED
File without changes
|
data/bin/test
CHANGED
File without changes
|
@@ -106,14 +106,14 @@ VALUE backend_base_switch_fiber(VALUE backend, struct Backend_base *base) {
|
|
106
106
|
|
107
107
|
void backend_base_schedule_fiber(VALUE thread, VALUE backend, struct Backend_base *base, VALUE fiber, VALUE value, int prioritize) {
|
108
108
|
int already_runnable;
|
109
|
+
runqueue_t *runqueue;
|
109
110
|
|
110
111
|
if (rb_fiber_alive_p(fiber) != Qtrue) return;
|
111
112
|
already_runnable = rb_ivar_get(fiber, ID_ivar_runnable) != Qnil;
|
112
113
|
|
113
114
|
COND_TRACE(base, 4, SYM_fiber_schedule, fiber, value, prioritize ? Qtrue : Qfalse);
|
114
115
|
|
115
|
-
|
116
|
-
&base->parked_runqueue : &base->runqueue;
|
116
|
+
runqueue = rb_ivar_get(fiber, ID_ivar_parked) == Qtrue ? &base->parked_runqueue : &base->runqueue;
|
117
117
|
|
118
118
|
(prioritize ? runqueue_unshift : runqueue_push)(runqueue, fiber, value, already_runnable);
|
119
119
|
if (!already_runnable) {
|
@@ -206,6 +206,36 @@ inline VALUE io_enc_str(VALUE str, rb_io_t *fptr) {
|
|
206
206
|
return str;
|
207
207
|
}
|
208
208
|
|
209
|
+
static inline void free_io_buffer(rb_io_buffer_t *buf)
|
210
|
+
{
|
211
|
+
if (buf->ptr) {
|
212
|
+
ruby_xfree(buf->ptr);
|
213
|
+
buf->ptr = NULL;
|
214
|
+
}
|
215
|
+
}
|
216
|
+
|
217
|
+
static inline void clear_codeconv(rb_io_t *fptr) {
|
218
|
+
if (fptr->readconv) {
|
219
|
+
rb_econv_close(fptr->readconv);
|
220
|
+
fptr->readconv = NULL;
|
221
|
+
}
|
222
|
+
free_io_buffer(&fptr->cbuf);
|
223
|
+
|
224
|
+
if (fptr->writeconv) {
|
225
|
+
rb_econv_close(fptr->writeconv);
|
226
|
+
fptr->writeconv = NULL;
|
227
|
+
}
|
228
|
+
fptr->writeconv_initialized = 0;
|
229
|
+
}
|
230
|
+
|
231
|
+
void fptr_finalize(rb_io_t *fptr) {
|
232
|
+
fptr->fd = -1;
|
233
|
+
fptr->stdio_file = 0;
|
234
|
+
free_io_buffer(&fptr->rbuf);
|
235
|
+
free_io_buffer(&fptr->wbuf);
|
236
|
+
clear_codeconv(fptr);
|
237
|
+
}
|
238
|
+
|
209
239
|
//////////////////////////////////////////////////////////////////////
|
210
240
|
//////////////////////////////////////////////////////////////////////
|
211
241
|
|
@@ -238,17 +268,22 @@ inline void rectify_io_file_pos(rb_io_t *fptr) {
|
|
238
268
|
|
239
269
|
inline double current_time() {
|
240
270
|
struct timespec ts;
|
271
|
+
double t;
|
272
|
+
uint64_t ns;
|
273
|
+
|
241
274
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
242
|
-
|
275
|
+
ns = ts.tv_sec;
|
243
276
|
ns = ns * 1e9 + ts.tv_nsec;
|
244
|
-
|
277
|
+
t = ns;
|
245
278
|
return t / 1e9;
|
246
279
|
}
|
247
280
|
|
248
281
|
inline uint64_t current_time_ns() {
|
249
282
|
struct timespec ts;
|
283
|
+
uint64_t ns;
|
284
|
+
|
250
285
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
251
|
-
|
286
|
+
ns = ts.tv_sec;
|
252
287
|
return ns * 1e9 + ts.tv_nsec;
|
253
288
|
}
|
254
289
|
|
@@ -276,6 +311,9 @@ VALUE Backend_timeout_ensure_safe(VALUE arg) {
|
|
276
311
|
static VALUE empty_string = Qnil;
|
277
312
|
|
278
313
|
VALUE Backend_sendv(VALUE self, VALUE io, VALUE ary, VALUE flags) {
|
314
|
+
VALUE joined;
|
315
|
+
VALUE result;
|
316
|
+
|
279
317
|
switch (RARRAY_LEN(ary)) {
|
280
318
|
case 0:
|
281
319
|
return Qnil;
|
@@ -286,14 +324,16 @@ VALUE Backend_sendv(VALUE self, VALUE io, VALUE ary, VALUE flags) {
|
|
286
324
|
empty_string = rb_str_new_literal("");
|
287
325
|
rb_global_variable(&empty_string);
|
288
326
|
}
|
289
|
-
|
290
|
-
|
327
|
+
joined = rb_ary_join(ary, empty_string);
|
328
|
+
result = Backend_send(self, io, joined, flags);
|
291
329
|
RB_GC_GUARD(joined);
|
292
330
|
return result;
|
293
331
|
}
|
294
332
|
}
|
295
333
|
|
296
334
|
inline void io_verify_blocking_mode(rb_io_t *fptr, VALUE io, VALUE blocking) {
|
335
|
+
int flags;
|
336
|
+
int is_nonblocking;
|
297
337
|
VALUE blocking_mode = rb_ivar_get(io, ID_ivar_blocking_mode);
|
298
338
|
if (blocking == blocking_mode) return;
|
299
339
|
|
@@ -303,9 +343,9 @@ inline void io_verify_blocking_mode(rb_io_t *fptr, VALUE io, VALUE blocking) {
|
|
303
343
|
if (blocking != Qtrue)
|
304
344
|
rb_w32_set_nonblock(fptr->fd);
|
305
345
|
#elif defined(F_GETFL)
|
306
|
-
|
346
|
+
flags = fcntl(fptr->fd, F_GETFL);
|
307
347
|
if (flags == -1) return;
|
308
|
-
|
348
|
+
is_nonblocking = flags & O_NONBLOCK;
|
309
349
|
|
310
350
|
if (blocking == Qtrue) {
|
311
351
|
if (!is_nonblocking) return;
|
@@ -319,12 +359,14 @@ inline void io_verify_blocking_mode(rb_io_t *fptr, VALUE io, VALUE blocking) {
|
|
319
359
|
}
|
320
360
|
|
321
361
|
inline void backend_run_idle_tasks(struct Backend_base *base) {
|
362
|
+
double now;
|
363
|
+
|
322
364
|
if (base->idle_proc != Qnil)
|
323
365
|
rb_funcall(base->idle_proc, ID_call, 0);
|
324
366
|
|
325
367
|
if (base->idle_gc_period == 0) return;
|
326
368
|
|
327
|
-
|
369
|
+
now = current_time();
|
328
370
|
if (now - base->idle_gc_last_time < base->idle_gc_period) return;
|
329
371
|
|
330
372
|
base->idle_gc_last_time = now;
|
@@ -389,4 +431,26 @@ void backend_setup_stats_symbols() {
|
|
389
431
|
rb_global_variable(&SYM_switch_count);
|
390
432
|
rb_global_variable(&SYM_poll_count);
|
391
433
|
rb_global_variable(&SYM_pending_ops);
|
392
|
-
}
|
434
|
+
}
|
435
|
+
|
436
|
+
int backend_getaddrinfo(VALUE host, VALUE port, struct sockaddr **ai_addr) {
|
437
|
+
VALUE port_string;
|
438
|
+
struct addrinfo hints;
|
439
|
+
struct addrinfo *addrinfo_result;
|
440
|
+
int ret;
|
441
|
+
|
442
|
+
memset(&hints, 0, sizeof(struct addrinfo));
|
443
|
+
hints.ai_family = AF_UNSPEC; /* allow IPv4 or IPv6 */
|
444
|
+
hints.ai_socktype = SOCK_STREAM;
|
445
|
+
|
446
|
+
port_string = rb_funcall(port, ID_to_s, 0);
|
447
|
+
ret = getaddrinfo(StringValueCStr(host), StringValueCStr(port_string), &hints, &addrinfo_result);
|
448
|
+
RB_GC_GUARD(port_string);
|
449
|
+
if (ret != 0) {
|
450
|
+
VALUE msg = rb_str_new2(gai_strerror(ret));
|
451
|
+
rb_funcall(rb_mKernel, ID_raise, 1, msg);
|
452
|
+
RB_GC_GUARD(msg);
|
453
|
+
}
|
454
|
+
*ai_addr = addrinfo_result->ai_addr;
|
455
|
+
return addrinfo_result->ai_addrlen;
|
456
|
+
}
|
@@ -1,6 +1,11 @@
|
|
1
1
|
#ifndef BACKEND_COMMON_H
|
2
2
|
#define BACKEND_COMMON_H
|
3
3
|
|
4
|
+
#include <sys/types.h>
|
5
|
+
#include <arpa/inet.h>
|
6
|
+
#include <netinet/in.h>
|
7
|
+
#include <netdb.h>
|
8
|
+
|
4
9
|
#include "ruby.h"
|
5
10
|
#include "ruby/io.h"
|
6
11
|
#include "runqueue.h"
|
@@ -68,6 +73,7 @@ void io_shrink_read_string(VALUE str, long n);
|
|
68
73
|
void io_set_read_length(VALUE str, long n, int shrinkable);
|
69
74
|
rb_encoding* io_read_encoding(rb_io_t *fptr);
|
70
75
|
VALUE io_enc_str(VALUE str, rb_io_t *fptr);
|
76
|
+
void fptr_finalize(rb_io_t *fptr);
|
71
77
|
|
72
78
|
//////////////////////////////////////////////////////////////////////
|
73
79
|
//////////////////////////////////////////////////////////////////////
|
@@ -109,5 +115,6 @@ VALUE Backend_stats(VALUE self);
|
|
109
115
|
void backend_run_idle_tasks(struct Backend_base *base);
|
110
116
|
void io_verify_blocking_mode(rb_io_t *fptr, VALUE io, VALUE blocking);
|
111
117
|
void backend_setup_stats_symbols();
|
118
|
+
int backend_getaddrinfo(VALUE host, VALUE port, struct sockaddr **ai_addr);
|
112
119
|
|
113
120
|
#endif /* BACKEND_COMMON_H */
|