From 91e366cbfca30f1dd158c86e51ee5fa3250e2272 Mon Sep 17 00:00:00 2001 From: Florian Dejonckheere Date: Mon, 25 Mar 2024 08:41:38 +0200 Subject: [PATCH 01/10] Add Ruby 3.3 to CI version matrix --- .github/workflows/test.yml | 2 +- .github/workflows/test_io_uring.yml | 2 +- .rubocop.yml | 4 ++-- CHANGELOG.md | 6 +++++- README.md | 2 +- docs/advanced-io.md | 4 ++-- docs/readme.md | 2 +- 7 files changed, 13 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bf48e4b9..09c0b5e3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,7 +8,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest] - ruby: ['3.1', '3.2', 'head'] + ruby: ['3.1', '3.2', '3.3', 'head'] name: >- ${{matrix.os}}, ${{matrix.ruby}} diff --git a/.github/workflows/test_io_uring.yml b/.github/workflows/test_io_uring.yml index b7d3afcf..ec3fdc94 100644 --- a/.github/workflows/test_io_uring.yml +++ b/.github/workflows/test_io_uring.yml @@ -8,7 +8,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - ruby: ['3.1', '3.2', 'head'] + ruby: ['3.1', '3.2', '3.3', 'head'] name: >- ${{matrix.os}}, ${{matrix.ruby}} diff --git a/.rubocop.yml b/.rubocop.yml index c27956f9..13c77979 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,5 @@ AllCops: - TargetRubyVersion: 3.2 + TargetRubyVersion: 3.3 RubyInterpreters: - ruby Exclude: @@ -202,4 +202,4 @@ Style/SlicingWithRange: Style/RaiseArgs: Exclude: - - lib/polyphony/extensions/fiber.rb \ No newline at end of file + - lib/polyphony/extensions/fiber.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 1def604b..c1e0edae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## Unreleased + +- Add support for Ruby 3.3 + ## 1.6 2023-08-05 - Refactor exception instantiation @@ -912,4 +916,4 @@ - Promised threads - HTTP server - Redis interface -- PostgreSQL interface \ No newline at end of file +- PostgreSQL interface diff --git a/README.md b/README.md index 4a6af0e9..cc3b68de 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ ## What is Polyphony? Polyphony is a library for building concurrent applications in Ruby. Polyphony -harnesses the power of [Ruby fibers](https://rubyapi.org/3.2/o/fiber) to provide +harnesses the power of [Ruby fibers](https://rubyapi.org/3.3/o/fiber) to provide a cooperative, sequential coroutine-based concurrency model. Under the hood, Polyphony uses [io_uring](https://unixism.net/loti/what_is_io_uring.html) or [libev](https://github.com/enki/libev) to maximize I/O performance. diff --git a/docs/advanced-io.md b/docs/advanced-io.md index 7de4d4d0..22919645 100644 --- a/docs/advanced-io.md +++ b/docs/advanced-io.md @@ -119,7 +119,7 @@ minimizing memory use and GC pressure. ## Compressing and decompressing in-flight data You might be familiar with Ruby's [zlib](https://github.com/ruby/zlib) gem (docs -[here](https://rubyapi.org/3.2/o/zlib)), which can be used to compress and +[here](https://rubyapi.org/3.3/o/zlib)), which can be used to compress and uncompress data using the popular gzip format. Imagine we want to implement an HTTP server that can serve files compressed using gzip: @@ -318,4 +318,4 @@ provided by Polyphony, which lets us write less code, have it run faster, have it run concurrently, and minimize memory allocations and pressure on the Ruby GC. Feel free to browse the [IO examples](https://github.com/digital-fabric/polyphony/tree/master/examples/io) -included in Polyphony. \ No newline at end of file +included in Polyphony. diff --git a/docs/readme.md b/docs/readme.md index ac8b8afb..47a6feb8 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -25,7 +25,7 @@ ## What is Polyphony? Polyphony is a library for building concurrent applications in Ruby. Polyphony -harnesses the power of [Ruby fibers](https://rubyapi.org/3.2/o/fiber) to provide +harnesses the power of [Ruby fibers](https://rubyapi.org/3.3/o/fiber) to provide a cooperative, sequential coroutine-based concurrency model. Under the hood, Polyphony uses [io_uring](https://unixism.net/loti/what_is_io_uring.html) or [libev](https://github.com/enki/libev) to maximize I/O performance. From e1344a6843864f95ab897c1ec58941d8aafab72e Mon Sep 17 00:00:00 2001 From: Florian Dejonckheere Date: Tue, 29 Apr 2025 10:29:26 +0200 Subject: [PATCH 02/10] Add Ruby 3.4 to CI version matrix --- .github/workflows/test.yml | 2 +- .github/workflows/test_io_uring.yml | 2 +- .rubocop.yml | 2 +- CHANGELOG.md | 2 +- README.md | 2 +- docs/advanced-io.md | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 09c0b5e3..9fc2fb3b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,7 +8,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest] - ruby: ['3.1', '3.2', '3.3', 'head'] + ruby: ['3.1', '3.2', '3.3', '3.4', 'head'] name: >- ${{matrix.os}}, ${{matrix.ruby}} diff --git a/.github/workflows/test_io_uring.yml b/.github/workflows/test_io_uring.yml index ec3fdc94..f1d1b2c7 100644 --- a/.github/workflows/test_io_uring.yml +++ b/.github/workflows/test_io_uring.yml @@ -8,7 +8,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - ruby: ['3.1', '3.2', '3.3', 'head'] + ruby: ['3.1', '3.2', '3.3', '3.4', 'head'] name: >- ${{matrix.os}}, ${{matrix.ruby}} diff --git a/.rubocop.yml b/.rubocop.yml index 13c77979..b3d75fb4 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,5 @@ AllCops: - TargetRubyVersion: 3.3 + TargetRubyVersion: 3.4 RubyInterpreters: - ruby Exclude: diff --git a/CHANGELOG.md b/CHANGELOG.md index c1e0edae..2d893585 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ## Unreleased -- Add support for Ruby 3.3 +- Add support for Ruby 3.3 and 3.4 ## 1.6 2023-08-05 diff --git a/README.md b/README.md index cc3b68de..8cd6ecac 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ ## What is Polyphony? Polyphony is a library for building concurrent applications in Ruby. Polyphony -harnesses the power of [Ruby fibers](https://rubyapi.org/3.3/o/fiber) to provide +harnesses the power of [Ruby fibers](https://rubyapi.org/3.4/o/fiber) to provide a cooperative, sequential coroutine-based concurrency model. Under the hood, Polyphony uses [io_uring](https://unixism.net/loti/what_is_io_uring.html) or [libev](https://github.com/enki/libev) to maximize I/O performance. diff --git a/docs/advanced-io.md b/docs/advanced-io.md index 22919645..c068fc23 100644 --- a/docs/advanced-io.md +++ b/docs/advanced-io.md @@ -119,7 +119,7 @@ minimizing memory use and GC pressure. ## Compressing and decompressing in-flight data You might be familiar with Ruby's [zlib](https://github.com/ruby/zlib) gem (docs -[here](https://rubyapi.org/3.3/o/zlib)), which can be used to compress and +[here](https://rubyapi.org/3.4/o/zlib)), which can be used to compress and uncompress data using the popular gzip format. Imagine we want to implement an HTTP server that can serve files compressed using gzip: From 3d4be1776379c7eeb778683e6cb1765a94f17744 Mon Sep 17 00:00:00 2001 From: Florian Dejonckheere Date: Tue, 29 Apr 2025 10:41:41 +0200 Subject: [PATCH 03/10] Remove unsupported Ruby 3.1 from CI version matrix --- .github/workflows/test.yml | 2 +- .github/workflows/test_io_uring.yml | 2 +- CHANGELOG.md | 1 + polyphony.gemspec | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9fc2fb3b..52575a77 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,7 +8,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest] - ruby: ['3.1', '3.2', '3.3', '3.4', 'head'] + ruby: ['3.2', '3.3', '3.4', 'head'] name: >- ${{matrix.os}}, ${{matrix.ruby}} diff --git a/.github/workflows/test_io_uring.yml b/.github/workflows/test_io_uring.yml index f1d1b2c7..69553047 100644 --- a/.github/workflows/test_io_uring.yml +++ b/.github/workflows/test_io_uring.yml @@ -8,7 +8,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - ruby: ['3.1', '3.2', '3.3', '3.4', 'head'] + ruby: ['3.2', '3.3', '3.4', 'head'] name: >- ${{matrix.os}}, ${{matrix.ruby}} diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d893585..09790a52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## Unreleased - Add support for Ruby 3.3 and 3.4 +- Remove support for Ruby 3.1 ## 1.6 2023-08-05 diff --git a/polyphony.gemspec b/polyphony.gemspec index 2a27afce..162fcc35 100644 --- a/polyphony.gemspec +++ b/polyphony.gemspec @@ -18,7 +18,7 @@ Gem::Specification.new do |s| s.extra_rdoc_files = ["README.md"] s.extensions = ["ext/polyphony/extconf.rb"] s.require_paths = ["lib"] - s.required_ruby_version = '>= 3.1' + s.required_ruby_version = '>= 3.2' s.add_development_dependency 'rake-compiler', '1.2.1' s.add_development_dependency 'minitest', '5.17.0' From fe7c4f8e959dedb86f572d554f20842da37699cc Mon Sep 17 00:00:00 2001 From: Florian Dejonckheere Date: Mon, 25 Mar 2024 08:52:42 +0200 Subject: [PATCH 04/10] Update development dependencies --- .rubocop.yml | 1 + polyphony.gemspec | 18 +++++++++--------- test/helper.rb | 1 + 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index b3d75fb4..ba8fc349 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -9,6 +9,7 @@ AllCops: - 'Gemfile*' - 'ext/**/*.rb' - lib/polyphony/adapters/irb.rb + NewCops: enable Style/LambdaCall: Enabled: false diff --git a/polyphony.gemspec b/polyphony.gemspec index 162fcc35..4f2b751b 100644 --- a/polyphony.gemspec +++ b/polyphony.gemspec @@ -20,15 +20,15 @@ Gem::Specification.new do |s| s.require_paths = ["lib"] s.required_ruby_version = '>= 3.2' - s.add_development_dependency 'rake-compiler', '1.2.1' - s.add_development_dependency 'minitest', '5.17.0' + s.add_development_dependency 'rake-compiler', '1.3.0' + s.add_development_dependency 'minitest', '5.25.5' s.add_development_dependency 'simplecov', '0.22.0' - s.add_development_dependency 'rubocop', '1.45.1' - s.add_development_dependency 'pry', '0.14.2' + s.add_development_dependency 'rubocop', '1.62.1' + s.add_development_dependency 'pry', '0.15.2' - s.add_development_dependency 'msgpack', '1.6.0' - s.add_development_dependency 'httparty', '0.21.0' - s.add_development_dependency 'localhost', '1.1.10' - s.add_development_dependency 'debug', '1.8.0' - s.add_development_dependency 'benchmark-ips', '2.10.0' + s.add_development_dependency 'msgpack', '1.8.0' + s.add_development_dependency 'httparty', '0.23.1' + s.add_development_dependency 'localhost', '1.5.0' + s.add_development_dependency 'debug', '1.10.0' + s.add_development_dependency 'benchmark-ips', '2.14.0' end diff --git a/test/helper.rb b/test/helper.rb index 6d6ae3a8..b1f7780e 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -11,6 +11,7 @@ require_relative './eg' require 'minitest/autorun' +require 'minitest/unit' ::Exception.__disable_sanitized_backtrace__ = true From 77d1740808d781f7b30360907816f63a05bbe2aa Mon Sep 17 00:00:00 2001 From: Florian Dejonckheere Date: Mon, 25 Mar 2024 09:01:03 +0200 Subject: [PATCH 05/10] Update Github actions --- .github/workflows/test.yml | 2 +- .github/workflows/test_io_uring.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 52575a77..438a5832 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,7 +20,7 @@ jobs: steps: - name: Setup machine - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup Ruby uses: ruby/setup-ruby@v1 with: diff --git a/.github/workflows/test_io_uring.yml b/.github/workflows/test_io_uring.yml index 69553047..2250390e 100644 --- a/.github/workflows/test_io_uring.yml +++ b/.github/workflows/test_io_uring.yml @@ -16,7 +16,7 @@ jobs: runs-on: ${{matrix.os}} steps: - name: Checkout repository and submodules - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: submodules: recursive - name: Setup Ruby From a0134b6fe2ff9a2f2d8ae04ddbe8a8342762dff5 Mon Sep 17 00:00:00 2001 From: Florian Dejonckheere Date: Mon, 25 Mar 2024 08:38:42 +0200 Subject: [PATCH 06/10] Temporarily add bundled gems --- polyphony.gemspec | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/polyphony.gemspec b/polyphony.gemspec index 4f2b751b..6d801c06 100644 --- a/polyphony.gemspec +++ b/polyphony.gemspec @@ -31,4 +31,10 @@ Gem::Specification.new do |s| s.add_development_dependency 'localhost', '1.5.0' s.add_development_dependency 'debug', '1.10.0' s.add_development_dependency 'benchmark-ips', '2.14.0' + + # FIXME: remove gems when all other dependencies have bundled them (not part of stdlib since Ruby 3.4) + s.add_development_dependency 'base64', '0.2.0' + s.add_development_dependency 'bigdecimal', '3.1.9' + s.add_development_dependency 'csv', '3.3.4' + s.add_development_dependency 'mutex_m', '0.3.0' end From b818a92f7826ef84cc922c9c4e99bea979377c9b Mon Sep 17 00:00:00 2001 From: Florian Dejonckheere Date: Mon, 16 Sep 2024 09:14:02 +0200 Subject: [PATCH 07/10] Forward keyword arguments in Polyphony::ResourcePool --- CHANGELOG.md | 1 + lib/polyphony/core/resource_pool.rb | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09790a52..16104dba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - Add support for Ruby 3.3 and 3.4 - Remove support for Ruby 3.1 +- Forward keyword arguments in `Polyphony::ResourcePool` ## 1.6 2023-08-05 diff --git a/lib/polyphony/core/resource_pool.rb b/lib/polyphony/core/resource_pool.rb index 4613f8bd..a1f997de 100644 --- a/lib/polyphony/core/resource_pool.rb +++ b/lib/polyphony/core/resource_pool.rb @@ -56,9 +56,10 @@ def acquire(&block) # # @param sym [Symbol] method name # @param args [Array] method arguments + # @param kwargs [Hash] keyword arguments # @return [any] result of method call - def method_missing(sym, *args, &block) - acquire { |r| r.send(sym, *args, &block) } + def method_missing(sym, *args, **kwargs, &block) + acquire { |r| r.send(sym, *args, **kwargs, &block) } end # @!visibility private From 2250fb382d1caed71eeffa4ed27f059944e06e93 Mon Sep 17 00:00:00 2001 From: Florian Dejonckheere Date: Mon, 16 Sep 2024 10:33:16 +0200 Subject: [PATCH 08/10] Cancel Github Actions workflow in progress --- .github/workflows/test.yml | 4 ++++ .github/workflows/test_io_uring.yml | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 438a5832..b083aeac 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,6 +13,10 @@ jobs: name: >- ${{matrix.os}}, ${{matrix.ruby}} + concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-${{matrix.os}}-${{matrix.ruby}}-libev + cancel-in-progress: true + runs-on: ${{matrix.os}} env: diff --git a/.github/workflows/test_io_uring.yml b/.github/workflows/test_io_uring.yml index 2250390e..4a47e635 100644 --- a/.github/workflows/test_io_uring.yml +++ b/.github/workflows/test_io_uring.yml @@ -13,7 +13,12 @@ jobs: name: >- ${{matrix.os}}, ${{matrix.ruby}} + concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-${{matrix.os}}-${{matrix.ruby}}-io_uring + cancel-in-progress: true + runs-on: ${{matrix.os}} + steps: - name: Checkout repository and submodules uses: actions/checkout@v4 From 20d5cd4552e2498adacb8003bbe61a848ba1cca4 Mon Sep 17 00:00:00 2001 From: Florian Dejonckheere Date: Mon, 16 Sep 2024 11:15:49 +0200 Subject: [PATCH 09/10] Fix inspect format for Ruby >= 3.4.0 --- test/helper.rb | 8 ++++++++ test/test_fiber.rb | 5 +++-- test/test_thread.rb | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/test/helper.rb b/test/helper.rb index b1f7780e..008b9f67 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -45,6 +45,14 @@ def format_trace(args) def monotonic_clock ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) end + + def inspect_method_name_for(klass_name, method_name) + if RUBY_VERSION < '3.4.0' + "`#{method_name}'" + else + "'#{klass_name}##{method_name}'" + end + end end class MiniTest::Test diff --git a/test/test_fiber.rb b/test/test_fiber.rb index 3657ea4d..e4c85479 100644 --- a/test/test_fiber.rb +++ b/test/test_fiber.rb @@ -619,7 +619,7 @@ def test_inspect f = spin(:baz) { :foo } expected = format( - '#', + "#", f.object_id, __FILE__, spin_line_no @@ -627,8 +627,9 @@ def test_inspect assert_equal expected, f.inspect f.await + expected = format( - '#', + "#", f.object_id, __FILE__, spin_line_no diff --git a/test/test_thread.rb b/test/test_thread.rb index 21b434c1..72d9649f 100644 --- a/test/test_thread.rb +++ b/test/test_thread.rb @@ -133,7 +133,7 @@ def test_that_suspend_returns_immediately_if_no_watchers Thread.backend.trace_proc = proc {|*r| records << r } suspend assert_equal [ - [:block, Fiber.current, ["#{__FILE__}:#{__LINE__ - 2}:in `test_that_suspend_returns_immediately_if_no_watchers'"] + caller] + [:block, Fiber.current, ["#{__FILE__}:#{__LINE__ - 2}:in #{inspect_method_name_for(self.class.name, __method__.to_s)}"] + caller] ], records ensure Thread.backend.trace_proc = nil From cc37abd534efce798246d019a0f8c3a7637ec74f Mon Sep 17 00:00:00 2001 From: Florian Dejonckheere Date: Mon, 2 Dec 2024 15:13:27 -0300 Subject: [PATCH 10/10] Use kwargs instead of empty hash argument --- lib/polyphony/extensions/io.rb | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/lib/polyphony/extensions/io.rb b/lib/polyphony/extensions/io.rb index dbf315fb..ab2b0570 100644 --- a/lib/polyphony/extensions/io.rb +++ b/lib/polyphony/extensions/io.rb @@ -27,20 +27,17 @@ def binwrite(name, string, offset = nil) end end - # @!visibility private - EMPTY_HASH = {}.freeze - # @!visibility private alias_method :orig_foreach, :foreach # @!visibility private - def foreach(name, sep = $/, limit = nil, getline_args = EMPTY_HASH, &block) + def foreach(name, sep = $/, limit = nil, **kwargs, &block) if sep.is_a?(Integer) sep = $/ limit = sep end File.open(name, 'r') do |f| - f.each_line(sep, limit, chomp: getline_args[:chomp], &block) + f.each_line(sep, limit, chomp: kwargs[:chomp], &block) end end @@ -48,21 +45,21 @@ def foreach(name, sep = $/, limit = nil, getline_args = EMPTY_HASH, &block) alias_method :orig_read, :read # @!visibility private - def read(name, length = nil, offset = nil, opt = EMPTY_HASH) + def read(name, length = nil, offset = nil, **kwargs) if length.is_a?(Hash) - opt = length + kwargs = length length = nil end - File.open(name, opt[:mode] || 'r') do |f| + File.open(name, kwargs[:mode] || 'r') do |f| f.seek(offset) if offset length ? f.read(length) : f.read end end alias_method :orig_readlines, :readlines - def readlines(name, sep = $/, limit = nil, getline_args = EMPTY_HASH) + def readlines(name, sep = $/, limit = nil, **kwargs) File.open(name, 'r') do |f| - f.readlines(sep, **getline_args) + f.readlines(sep, **kwargs) end end @@ -70,8 +67,8 @@ def readlines(name, sep = $/, limit = nil, getline_args = EMPTY_HASH) alias_method :orig_write, :write # @!visibility private - def write(name, string, offset = nil, opt = EMPTY_HASH) - File.open(name, opt[:mode] || 'w') do |f| + def write(name, string, offset = nil, **kwargs) + File.open(name, kwargs[:mode] || 'w') do |f| f.seek(offset) if offset f.write(string) end