diff --git a/rack-async-http-falcon-async-await/.ruby-version b/rack-async-http-falcon-async-await/.ruby-version new file mode 100644 index 0000000..37c2961 --- /dev/null +++ b/rack-async-http-falcon-async-await/.ruby-version @@ -0,0 +1 @@ +2.7.2 diff --git a/rack-async-http-falcon-async-await/Gemfile b/rack-async-http-falcon-async-await/Gemfile new file mode 100644 index 0000000..dc4e8ac --- /dev/null +++ b/rack-async-http-falcon-async-await/Gemfile @@ -0,0 +1,8 @@ +source "https://rubygems.org" + +ruby "2.7.2" + +gem "rack" +gem "falcon" +gem "async-http" +gem "async-await" diff --git a/rack-async-http-falcon-async-await/Gemfile.lock b/rack-async-http-falcon-async-await/Gemfile.lock new file mode 100644 index 0000000..1aa14cb --- /dev/null +++ b/rack-async-http-falcon-async-await/Gemfile.lock @@ -0,0 +1,76 @@ +GEM + remote: https://rubygems.org/ + specs: + async (1.28.9) + console (~> 1.10) + nio4r (~> 2.3) + timers (~> 4.1) + async-await (0.5.0) + async (~> 1.3) + ruby2_keywords + async-container (0.16.8) + async (~> 1.0) + async-io (~> 1.26) + async-http (0.54.1) + async (~> 1.25) + async-io (~> 1.28) + async-pool (~> 0.2) + protocol-http (~> 0.21.0) + protocol-http1 (~> 0.13.0) + protocol-http2 (~> 0.14.0) + async-http-cache (0.3.0) + async-http (~> 0.53) + async-io (1.30.2) + async (~> 1.14) + async-pool (0.3.5) + async (~> 1.25) + build-environment (1.13.0) + console (1.10.2) + fiber-local + falcon (0.37.3) + async (~> 1.13) + async-container (~> 0.16.0) + async-http (~> 0.54.0) + async-http-cache (~> 0.3.0) + async-io (~> 1.22) + build-environment (~> 1.13) + bundler + localhost (~> 1.1) + process-metrics (~> 0.2.0) + rack (>= 1.0) + samovar (~> 2.1) + fiber-local (1.0.0) + localhost (1.1.7) + mapping (1.1.1) + nio4r (2.5.7) + process-metrics (0.2.1) + console (~> 1.8) + samovar (~> 2.1) + protocol-hpack (1.4.2) + protocol-http (0.21.0) + protocol-http1 (0.13.2) + protocol-http (~> 0.19) + protocol-http2 (0.14.2) + protocol-hpack (~> 1.4) + protocol-http (~> 0.18) + rack (2.2.3) + ruby2_keywords (0.0.4) + samovar (2.1.4) + console (~> 1.0) + mapping (~> 1.0) + timers (4.3.3) + +PLATFORMS + ruby + +DEPENDENCIES + async-await + async-http + falcon + rack + +RUBY VERSION + ruby 3.0.0p0 + +BUNDLED WITH + 2.2.5 diff --git a/rack-async-http-falcon-async-await/README.md b/rack-async-http-falcon-async-await/README.md new file mode 100644 index 0000000..8a94a54 --- /dev/null +++ b/rack-async-http-falcon-async-await/README.md @@ -0,0 +1,16 @@ +Example app using: + * rack + * falcon + * async-http + * async-await + + Notes: + * Based on rack-async-http-falcon-graphql-batch + * Uses async-await instead of graphql-batch loaders + +Running and benchmarking: + + falcon serve --count 1 + ab -n 100 -c 100 https://localhost:9292/ + +Benchmark results: diff --git a/rack-async-http-falcon-async-await/app.rb b/rack-async-http-falcon-async-await/app.rb new file mode 100644 index 0000000..d238c21 --- /dev/null +++ b/rack-async-http-falcon-async-await/app.rb @@ -0,0 +1,38 @@ +require "async/await" + +class App + class << self + include Async::Await + + sync def call(env) + puts "Request start" + + results = sort([5, 2, 3, 4, 9, 2, 5, 7, 8]).result + + puts "Request finish" + + [200, {}, [results.to_json]] + end + + async def sort_one(item, into) + sleep(item.to_f) + into << item + + puts "I've sorted #{item} for you." + end + + async def sort(items) + result = [] + + items.each do |item| + sort_one(item, result) + end + + puts "Waiting at the barrier!" + barrier! + + puts "Returning the result" + return result + end + end +end diff --git a/rack-async-http-falcon-async-await/config.ru b/rack-async-http-falcon-async-await/config.ru new file mode 100644 index 0000000..b929d04 --- /dev/null +++ b/rack-async-http-falcon-async-await/config.ru @@ -0,0 +1,7 @@ +require "rubygems" +require "bundler" +Bundler.require + +require_relative "app" + +run App