polyphony 0.99 → 0.99.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +1 -1
- data/.rubocop.yml +3 -3
- data/.yardopts +30 -0
- data/CHANGELOG.md +4 -0
- data/LICENSE +1 -1
- data/README.md +63 -29
- data/Rakefile +1 -5
- data/TODO.md +0 -4
- data/docs/{main-concepts/concurrency.md → concurrency.md} +2 -9
- data/docs/{main-concepts/design-principles.md → design-principles.md} +3 -9
- data/docs/{main-concepts/exception-handling.md → exception-handling.md} +2 -9
- data/docs/{main-concepts/extending.md → extending.md} +2 -9
- data/docs/faq.md +3 -16
- data/docs/{main-concepts/fiber-scheduling.md → fiber-scheduling.md} +1 -9
- data/docs/link_rewriter.rb +16 -0
- data/docs/{getting-started/overview.md → overview.md} +1 -30
- data/docs/{getting-started/tutorial.md → tutorial.md} +3 -28
- data/docs/{_posts/2020-07-26-polyphony-0.44.md → whats-new.md} +3 -1
- data/examples/adapters/redis_client.rb +3 -2
- data/examples/io/echo_server.rb +1 -1
- data/examples/io/echo_server_plain_ruby.rb +26 -0
- data/ext/polyphony/backend_io_uring.c +154 -9
- data/ext/polyphony/backend_io_uring_context.c +21 -12
- data/ext/polyphony/backend_io_uring_context.h +12 -7
- data/ext/polyphony/backend_libev.c +1 -1
- data/ext/polyphony/extconf.rb +24 -8
- data/ext/polyphony/fiber.c +79 -2
- data/ext/polyphony/io_extensions.c +53 -0
- data/ext/polyphony/pipe.c +42 -2
- data/ext/polyphony/polyphony.c +345 -31
- data/ext/polyphony/polyphony.h +9 -2
- data/ext/polyphony/queue.c +181 -0
- data/ext/polyphony/ring_buffer.c +0 -1
- data/ext/polyphony/runqueue.c +8 -1
- data/ext/polyphony/runqueue_ring_buffer.c +13 -0
- data/ext/polyphony/runqueue_ring_buffer.h +2 -1
- data/ext/polyphony/socket_extensions.c +6 -0
- data/ext/polyphony/thread.c +34 -2
- data/lib/polyphony/adapters/process.rb +11 -1
- data/lib/polyphony/adapters/sequel.rb +1 -1
- data/lib/polyphony/core/channel.rb +2 -0
- data/lib/polyphony/core/debug.rb +1 -1
- data/lib/polyphony/core/global_api.rb +25 -24
- data/lib/polyphony/core/resource_pool.rb +7 -6
- data/lib/polyphony/core/sync.rb +2 -2
- data/lib/polyphony/core/thread_pool.rb +3 -3
- data/lib/polyphony/core/timer.rb +8 -8
- data/lib/polyphony/extensions/exception.rb +2 -0
- data/lib/polyphony/extensions/fiber.rb +15 -13
- data/lib/polyphony/extensions/io.rb +127 -5
- data/lib/polyphony/extensions/kernel.rb +20 -2
- data/lib/polyphony/extensions/openssl.rb +100 -11
- data/lib/polyphony/extensions/pipe.rb +103 -7
- data/lib/polyphony/extensions/process.rb +13 -1
- data/lib/polyphony/extensions/socket.rb +93 -27
- data/lib/polyphony/extensions/thread.rb +9 -1
- data/lib/polyphony/extensions/timeout.rb +1 -1
- data/lib/polyphony/version.rb +2 -1
- data/lib/polyphony.rb +27 -7
- data/polyphony.gemspec +1 -8
- data/test/stress.rb +1 -1
- data/test/test_global_api.rb +45 -7
- data/test/test_socket.rb +96 -0
- data/test/test_timer.rb +5 -5
- metadata +17 -40
- data/docs/_config.yml +0 -64
- data/docs/_includes/head.html +0 -40
- data/docs/_includes/title.html +0 -1
- data/docs/_sass/custom/custom.scss +0 -10
- data/docs/_sass/overrides.scss +0 -0
- data/docs/api-reference/exception.md +0 -31
- data/docs/api-reference/fiber.md +0 -425
- data/docs/api-reference/index.md +0 -9
- data/docs/api-reference/io.md +0 -36
- data/docs/api-reference/object.md +0 -99
- data/docs/api-reference/polyphony-baseexception.md +0 -33
- data/docs/api-reference/polyphony-cancel.md +0 -26
- data/docs/api-reference/polyphony-moveon.md +0 -24
- data/docs/api-reference/polyphony-net.md +0 -20
- data/docs/api-reference/polyphony-process.md +0 -28
- data/docs/api-reference/polyphony-resourcepool.md +0 -59
- data/docs/api-reference/polyphony-restart.md +0 -18
- data/docs/api-reference/polyphony-terminate.md +0 -18
- data/docs/api-reference/polyphony-threadpool.md +0 -67
- data/docs/api-reference/polyphony-throttler.md +0 -77
- data/docs/api-reference/polyphony.md +0 -36
- data/docs/api-reference/thread.md +0 -88
- data/docs/favicon.ico +0 -0
- data/docs/getting-started/index.md +0 -10
- data/docs/getting-started/installing.md +0 -34
- /data/{docs/assets/img → assets}/echo-fibers.svg +0 -0
- /data/{docs → assets}/polyphony-logo.png +0 -0
- /data/{docs/assets/img → assets}/sleeping-fiber.svg +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f9f6713f2080b0ad929afc680c52a88ad737701575c30433e9ec4c759258dd7
|
4
|
+
data.tar.gz: c7f3fd09e72c34269624d52d8dc77e9f5645cfa2d65743afe51e07db850598e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3472d5ffee0ce36370701c98d28d33d9c76e7ac21a6635e4dff063a6d28e313cd518290dbd0904c496ec29471cab39922daf2473f6b9a168588d0ef861f5ff2
|
7
|
+
data.tar.gz: 2a230e7c9b2a95e24992d4a844b92a7af243da5113f355945ce8f585a415dafbde0e2f1fe2fcd1ba434bda94992a3cdf906e37ab78c01caa355e131c8103c87b
|
data/.github/FUNDING.yml
CHANGED
@@ -1 +1 @@
|
|
1
|
-
github:
|
1
|
+
github: noteflakes
|
data/.rubocop.yml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
AllCops:
|
2
|
-
TargetRubyVersion: 2
|
2
|
+
TargetRubyVersion: 3.2
|
3
3
|
RubyInterpreters:
|
4
4
|
- ruby
|
5
5
|
Exclude:
|
@@ -49,7 +49,7 @@ Style/NumericPredicate:
|
|
49
49
|
Style/TrivialAccessors:
|
50
50
|
Enabled: false
|
51
51
|
|
52
|
-
|
52
|
+
Lint/MissingSuper:
|
53
53
|
Enabled: false
|
54
54
|
|
55
55
|
Style/GlobalVars:
|
@@ -90,7 +90,7 @@ Metrics/MethodLength:
|
|
90
90
|
|
91
91
|
Metrics/ModuleLength:
|
92
92
|
Exclude:
|
93
|
-
- lib/polyphony/
|
93
|
+
- lib/polyphony/core/global_api.rb
|
94
94
|
- examples/**/*.rb
|
95
95
|
|
96
96
|
Metrics/ClassLength:
|
data/.yardopts
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
-o ./_yardoc
|
2
|
+
-m markdown -M redcarpet
|
3
|
+
--verbose
|
4
|
+
--protected
|
5
|
+
--no-private
|
6
|
+
--asset assets/:assets
|
7
|
+
--exclude debugger.rb
|
8
|
+
--exclude redis.rb
|
9
|
+
--exclude readline.rb
|
10
|
+
--exclude postgres.rb
|
11
|
+
--exclude zlib_conf.rb
|
12
|
+
--exclude extconf.rb
|
13
|
+
--exclude mysql2.rb
|
14
|
+
--exclude sequel.rb
|
15
|
+
--exclude event.c
|
16
|
+
--exclude backend.+\.c
|
17
|
+
--load ./docs/link_rewriter.rb
|
18
|
+
./lib
|
19
|
+
./ext/polyphony
|
20
|
+
-
|
21
|
+
docs/overview.md
|
22
|
+
docs/tutorial.md
|
23
|
+
docs/faq.md
|
24
|
+
docs/concurrency.md
|
25
|
+
docs/fiber-scheduling.md
|
26
|
+
docs/exception-handling.md
|
27
|
+
docs/extending.md
|
28
|
+
docs/design-principles.md
|
29
|
+
CHANGELOG.md
|
30
|
+
LICENSE
|
data/CHANGELOG.md
CHANGED
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,36 +1,26 @@
|
|
1
|
-
<
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
<
|
13
|
-
|
14
|
-
<img src="https://badge.fury.io/rb/polyphony.svg" alt="Ruby gem">
|
15
|
-
</a>
|
16
|
-
<a href="https://github.com/digital-fabric/polyphony/actions?query=workflow%3ATests">
|
17
|
-
<img src="https://github.com/digital-fabric/polyphony/workflows/Tests/badge.svg" alt="Tests">
|
18
|
-
</a>
|
19
|
-
<a href="https://github.com/digital-fabric/polyphony/blob/master/LICENSE">
|
20
|
-
<img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="MIT License">
|
21
|
-
</a>
|
22
|
-
</p>
|
23
|
-
|
24
|
-
[DOCS](https://digital-fabric.github.io/polyphony/) |
|
25
|
-
[EXAMPLES](examples)
|
1
|
+
<img src="assets/polyphony-logo.png" alt="Polyphony">
|
2
|
+
|
3
|
+
# Polyphony: Fine-Grained Concurrency for Ruby
|
4
|
+
|
5
|
+
<a href="http://rubygems.org/gems/polyphony">
|
6
|
+
<img src="https://badge.fury.io/rb/polyphony.svg" alt="Ruby gem">
|
7
|
+
</a>
|
8
|
+
<a href="https://github.com/digital-fabric/polyphony/actions?query=workflow%3ATests">
|
9
|
+
<img src="https://github.com/digital-fabric/polyphony/workflows/Tests/badge.svg" alt="Tests">
|
10
|
+
</a>
|
11
|
+
<a href="https://github.com/digital-fabric/polyphony/blob/master/LICENSE">
|
12
|
+
<img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="MIT License">
|
13
|
+
</a>
|
26
14
|
|
27
15
|
> Polyphony \| pəˈlɪf\(ə\)ni \|
|
16
|
+
>
|
28
17
|
> 1. _Music_ the style of simultaneously combining a number of parts, each
|
29
18
|
> forming an individual melody and harmonizing with each other.
|
19
|
+
>
|
30
20
|
> 2. _Programming_ a Ruby gem for concurrent programming focusing on performance
|
31
21
|
> and developer happiness.
|
32
22
|
|
33
|
-
## What is Polyphony
|
23
|
+
## What is Polyphony?
|
34
24
|
|
35
25
|
Polyphony is a library for building concurrent applications in Ruby. Polyphony
|
36
26
|
harnesses the power of [Ruby fibers](https://ruby-doc.org/core-2.5.1/Fiber.html)
|
@@ -54,10 +44,54 @@ the hood, Polyphony uses
|
|
54
44
|
* Competitive performance and scalability characteristics, in terms of both
|
55
45
|
throughput and memory consumption.
|
56
46
|
|
57
|
-
##
|
47
|
+
## Installing
|
48
|
+
|
49
|
+
### System Requirements
|
50
|
+
|
51
|
+
In order to use Polyphony you need to have:
|
52
|
+
|
53
|
+
- Linux or MacOS (support for Windows will come at a later stage)
|
54
|
+
- Ruby (MRI) 3.0 or newer
|
55
|
+
|
56
|
+
### Installing the Polyphony Gem
|
57
|
+
|
58
|
+
Add this line to your application's Gemfile:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
gem 'polyphony'
|
62
|
+
```
|
63
|
+
|
64
|
+
And then execute:
|
65
|
+
|
66
|
+
```bash
|
67
|
+
$ bundle
|
68
|
+
```
|
69
|
+
|
70
|
+
Or install it yourself as:
|
71
|
+
|
72
|
+
```bash
|
73
|
+
$ gem install polyphony
|
74
|
+
```
|
75
|
+
|
76
|
+
## Usage
|
77
|
+
|
78
|
+
- [Overview](docs/overview.md)
|
79
|
+
- [Tutorial](docs/tutorial.md)
|
80
|
+
- [FAQ](docs/faq.md)
|
81
|
+
|
82
|
+
## Technical Discussion
|
83
|
+
|
84
|
+
- [Concurrency the Easy Way](docs/concurrency.md)
|
85
|
+
- [How Fibers are Scheduled](docs/fiber-scheduling.md)
|
86
|
+
- [Exception Handling](docs/exception-handling.md)
|
87
|
+
- [Extending Polyphony](docs/extending.md)
|
88
|
+
- [Polyphony's Design](docs/design-principles.md)
|
89
|
+
|
90
|
+
## Examples
|
58
91
|
|
59
|
-
|
60
|
-
|
92
|
+
For examples of specific use cases you can consult the [bundled
|
93
|
+
examples](https://github.com/digital-fabric/polyphony/tree/master/examples) in
|
94
|
+
Polyphony's GitHub repository.
|
61
95
|
|
62
96
|
## Contributing to Polyphony
|
63
97
|
|
data/Rakefile
CHANGED
@@ -19,16 +19,12 @@ task :stress_test do
|
|
19
19
|
exec 'ruby test/stress.rb'
|
20
20
|
end
|
21
21
|
|
22
|
-
task :docs do
|
23
|
-
exec 'RUBYOPT=-W0 jekyll serve -s docs -H ec2-18-156-117-172.eu-central-1.compute.amazonaws.com'
|
24
|
-
end
|
25
|
-
|
26
22
|
CLEAN.include "**/*.o", "**/*.so", "**/*.so.*", "**/*.a", "**/*.bundle", "**/*.jar", "pkg", "tmp"
|
27
23
|
|
28
24
|
task :release do
|
29
25
|
require_relative './lib/polyphony/version'
|
30
26
|
version = Polyphony::VERSION
|
31
|
-
|
27
|
+
|
32
28
|
puts 'Building polyphony...'
|
33
29
|
`gem build polyphony.gemspec`
|
34
30
|
|
data/TODO.md
CHANGED
@@ -11,9 +11,6 @@
|
|
11
11
|
- Add support for IPv6:
|
12
12
|
https://www.reddit.com/r/ruby/comments/lyen23/understanding_ipv6_and_why_its_important_to_you/
|
13
13
|
|
14
|
-
- Add support for UDP sockets
|
15
|
-
|
16
|
-
- Check segfault when resetting a `cancel_after` timeout lots of times at very high rate
|
17
14
|
- Check why `throttled_loop` inside of `move_on_after` fails to stop
|
18
15
|
|
19
16
|
- Override stock `::SizedQueue` impl with Queue with capacity
|
@@ -165,7 +162,6 @@
|
|
165
162
|
- test performance
|
166
163
|
- proceed from there
|
167
164
|
|
168
|
-
|
169
165
|
### Sinatra / Sidekiq
|
170
166
|
|
171
167
|
- Pull out redis/postgres code, put into new `polyphony-xxx` gems
|
@@ -1,12 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
title: Concurrency the Easy Way
|
4
|
-
nav_order: 1
|
5
|
-
parent: Main Concepts
|
6
|
-
permalink: /main-concepts/concurrency/
|
7
|
-
prev_title: Tutorial
|
8
|
-
next_title: How Fibers are Scheduled
|
9
|
-
---
|
1
|
+
# @title Concurrency the Easy Way
|
2
|
+
|
10
3
|
# Concurrency the Easy Way
|
11
4
|
|
12
5
|
Concurrency is a major consideration for modern programmers. Applications and
|
@@ -1,12 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
nav_order: 5
|
5
|
-
parent: Main Concepts
|
6
|
-
permalink: /main-concepts/design-principles/
|
7
|
-
prev_title: Extending Polyphony
|
8
|
-
---
|
9
|
-
# The Design of Polyphony
|
1
|
+
# @title Polyphony's Design
|
2
|
+
|
3
|
+
# Polyphony's Design
|
10
4
|
|
11
5
|
Polyphony is a new gem that aims to enable developing high-performance
|
12
6
|
concurrent applications in Ruby using a fluent, compact syntax and API.
|
@@ -1,12 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
title: Exception Handling
|
4
|
-
nav_order: 3
|
5
|
-
parent: Main Concepts
|
6
|
-
permalink: /main-concepts/exception-handling/
|
7
|
-
prev_title: How Fibers are Scheduled
|
8
|
-
next_title: Extending Polyphony
|
9
|
-
---
|
1
|
+
# @title Exception Handling
|
2
|
+
|
10
3
|
# Exception Handling
|
11
4
|
|
12
5
|
Ruby employs a pretty robust exception handling mechanism. An raised exception
|
@@ -1,12 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
title: Extending Polyphony
|
4
|
-
nav_order: 4
|
5
|
-
parent: Main Concepts
|
6
|
-
permalink: /main-concepts/extending/
|
7
|
-
prev_title: Exception Handling
|
8
|
-
next_title: The Design of Polyphony
|
9
|
-
---
|
1
|
+
# @title Extending Polyphony
|
2
|
+
|
10
3
|
# Extending Polyphony
|
11
4
|
|
12
5
|
Polyphony was designed to ease the transition from blocking APIs and
|
data/docs/faq.md
CHANGED
@@ -1,19 +1,6 @@
|
|
1
|
-
|
2
|
-
layout: page
|
3
|
-
title: Frequently Asked Questions
|
4
|
-
nav_order: 100
|
5
|
-
---
|
1
|
+
# @title FAQ
|
6
2
|
|
7
3
|
# Frequently Asked Questions
|
8
|
-
{: .no_toc }
|
9
|
-
|
10
|
-
## Table of contents
|
11
|
-
{: .no_toc .text-delta }
|
12
|
-
|
13
|
-
- TOC
|
14
|
-
{:toc}
|
15
|
-
|
16
|
-
---
|
17
4
|
|
18
5
|
## Why not just use callbacks instead of fibers?
|
19
6
|
|
@@ -191,5 +178,5 @@ Feel free to create issues and contribute pull requests.
|
|
191
178
|
## Who is behind this project?
|
192
179
|
|
193
180
|
I'm Sharon Rosner, an independent software developer living in France. Here's my
|
194
|
-
[github profile](https://github.com/
|
195
|
-
[noteflakes
|
181
|
+
[github profile](https://github.com/noteflakes). You can contact me by writing to
|
182
|
+
[sharon@noteflakes.com](mailto:sharon@noteflakes.com).
|
@@ -1,12 +1,4 @@
|
|
1
|
-
|
2
|
-
layout: page
|
3
|
-
title: How Fibers are Scheduled
|
4
|
-
nav_order: 2
|
5
|
-
parent: Main Concepts
|
6
|
-
permalink: /main-concepts/fiber-scheduling/
|
7
|
-
prev_title: Concurrency the Easy Way
|
8
|
-
next_title: Exception Handling
|
9
|
-
---
|
1
|
+
# @title How Fibers are Scheduled
|
10
2
|
|
11
3
|
# How Fibers are Scheduled
|
12
4
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'yard'
|
2
|
+
|
3
|
+
# shamelessly copied from https://github.com/troessner/reek/blob/master/docs/yard_plugin.rb
|
4
|
+
|
5
|
+
# Template helper to modify processing of links in HTML generated from our
|
6
|
+
# markdown files.
|
7
|
+
module LocalLinkHelper
|
8
|
+
# Rewrites links to (assumed local) markdown files so they're processed as
|
9
|
+
# {file: } directives.
|
10
|
+
def resolve_links(text)
|
11
|
+
text = text.gsub(%r{<a href="(docs/[^"]*.md)">([^<]*)</a>}, '{file:/\1 \2}')
|
12
|
+
super text
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
YARD::Templates::Template.extra_includes << LocalLinkHelper
|
@@ -1,20 +1,6 @@
|
|
1
|
-
|
2
|
-
layout: page
|
3
|
-
title: Overview
|
4
|
-
parent: Getting Started
|
5
|
-
nav_order: 2
|
6
|
-
---
|
1
|
+
# @title Overview
|
7
2
|
|
8
3
|
# Polyphony - an Overview
|
9
|
-
{: .no_toc }
|
10
|
-
|
11
|
-
## Table of contents
|
12
|
-
{: .no_toc .text-delta }
|
13
|
-
|
14
|
-
- TOC
|
15
|
-
{:toc}
|
16
|
-
|
17
|
-
---
|
18
4
|
|
19
5
|
## Introduction
|
20
6
|
|
@@ -34,21 +20,6 @@ support for HTTP 1 & 2, WebSockets, TLS/SSL termination and more. Polyphony also
|
|
34
20
|
provides fiber-aware adapters for connecting to PostgreSQL and Redis servers.
|
35
21
|
More adapters are being actively developed.
|
36
22
|
|
37
|
-
### Features
|
38
|
-
{: .no_toc }
|
39
|
-
|
40
|
-
- Co-operative scheduling of concurrent tasks using Ruby fibers.
|
41
|
-
- High-performance event reactor for handling I/O, timer, and other events.
|
42
|
-
- Natural, sequential programming style that makes it easy to reason about
|
43
|
-
concurrent code.
|
44
|
-
- Abstractions and constructs for controlling the execution of concurrent code:
|
45
|
-
supervisors, cancel scopes, throttling, resource pools etc.
|
46
|
-
- Code can use native networking classes and libraries, growing support for
|
47
|
-
third-party gems such as pg and redis.
|
48
|
-
- Use stdlib classes such as TCPServer and TCPSocket and Net::HTTP.
|
49
|
-
- Impressive performance and scalability characteristics, in terms of both
|
50
|
-
throughput and memory consumption (see below)
|
51
|
-
|
52
23
|
## Taking Polyphony for a Spin
|
53
24
|
|
54
25
|
Polyphony is different from other reactor-based solutions for Ruby in that
|
@@ -1,20 +1,6 @@
|
|
1
|
-
|
2
|
-
layout: page
|
3
|
-
title: Tutorial
|
4
|
-
parent: Getting Started
|
5
|
-
nav_order: 3
|
6
|
-
---
|
1
|
+
# @title Tutorial
|
7
2
|
|
8
3
|
# Tutorial
|
9
|
-
{: .no_toc }
|
10
|
-
|
11
|
-
## Table of contents
|
12
|
-
{: .no_toc .text-delta }
|
13
|
-
|
14
|
-
- TOC
|
15
|
-
{:toc}
|
16
|
-
|
17
|
-
---
|
18
4
|
|
19
5
|
Polyphony is a new Ruby library aimed at making writing concurrent Ruby apps
|
20
6
|
easy and fun. In this article, we'll introduce Polyphony's fiber-based
|
@@ -108,7 +94,7 @@ The above program does nothing exceptional, it just sleeps for 1 second and
|
|
108
94
|
prints a bunch of messages. But it is enough to demonstrate how concurrency
|
109
95
|
works in Polyphony. Here's a flow chart of the transfer of control:
|
110
96
|
|
111
|
-
<
|
97
|
+
<img src="../assets/sleeping-fiber.svg">
|
112
98
|
|
113
99
|
Here's the actual sequence of execution (in pseudo-code)
|
114
100
|
|
@@ -203,7 +189,7 @@ innocent call to `#spin`.
|
|
203
189
|
|
204
190
|
Here's a flow chart showing the transfer of control between the different fibers:
|
205
191
|
|
206
|
-
<
|
192
|
+
<img src="../assets/echo-fibers.svg">
|
207
193
|
|
208
194
|
Let's consider the advantage of the Polyphony concurrency model:
|
209
195
|
|
@@ -346,14 +332,3 @@ Polyphony currently provides support for any library that uses Ruby's stock
|
|
346
332
|
`redis` and `irb` gems. It also includes an implementation of an integrated HTTP
|
347
333
|
1 / HTTP 2 / websockets web server with support for TLS termination, ALPN
|
348
334
|
protocol selection and preliminary rack support.
|
349
|
-
|
350
|
-
## Fibers are the Future!
|
351
|
-
|
352
|
-
Implementing concurrency at the level of fibers opens up so many new
|
353
|
-
possibilities for Ruby. Polyphony has the performance characteristics and
|
354
|
-
provides the necessary tools for transforming how concurrent Ruby apps are
|
355
|
-
written. Polyphony is still new, and the present documentation is far from being
|
356
|
-
complete. To learn more about Polyphony, read the [technical
|
357
|
-
overview](../../main-concepts/design-principles/). For more examples please
|
358
|
-
consult the [Github
|
359
|
-
repository](https://github.com/digital-fabric/polyphony/tree/master/examples).
|
data/examples/io/echo_server.rb
CHANGED
@@ -5,8 +5,8 @@ require 'polyphony'
|
|
5
5
|
|
6
6
|
spin_loop(interval: 5) { p Thread.backend.stats }
|
7
7
|
|
8
|
-
server = TCPServer.open('127.0.0.1', 1234)
|
9
8
|
puts "Pid: #{Process.pid}"
|
9
|
+
server = TCPServer.open('127.0.0.1', 1234)
|
10
10
|
puts 'Echoing on port 1234...'
|
11
11
|
begin
|
12
12
|
while (client = server.accept)
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'socket'
|
4
|
+
|
5
|
+
puts "Pid: #{Process.pid}"
|
6
|
+
server = TCPServer.open('127.0.0.1', 1234)
|
7
|
+
puts 'Echoing on port 1234...'
|
8
|
+
begin
|
9
|
+
while (client = server.accept)
|
10
|
+
Thread.new do
|
11
|
+
while (data = client.gets)
|
12
|
+
# client.send("you said: #{data.chomp}!\n", 0)
|
13
|
+
client.write('you said: ', data.chomp, "!\n")
|
14
|
+
end
|
15
|
+
rescue Errno::ECONNRESET
|
16
|
+
'Connection reset...'
|
17
|
+
ensure
|
18
|
+
puts "Closing client socket"
|
19
|
+
client.shutdown
|
20
|
+
client.close
|
21
|
+
end
|
22
|
+
end
|
23
|
+
ensure
|
24
|
+
puts "Closing server"
|
25
|
+
server.close
|
26
|
+
end
|