Skip to content

async-await (wip) #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rack-async-http-falcon-async-await/.ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.7.2
8 changes: 8 additions & 0 deletions rack-async-http-falcon-async-await/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
source "https://rubygems.org"

ruby "2.7.2"

gem "rack"
gem "falcon"
gem "async-http"
gem "async-await"
76 changes: 76 additions & 0 deletions rack-async-http-falcon-async-await/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions rack-async-http-falcon-async-await/README.md
Original file line number Diff line number Diff line change
@@ -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:
38 changes: 38 additions & 0 deletions rack-async-http-falcon-async-await/app.rb
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions rack-async-http-falcon-async-await/config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "rubygems"
require "bundler"
Bundler.require

require_relative "app"

run App