Upgrade to Pro — share decks privately, control downloads, hide ads and more …

faastCrystal

 faastCrystal

Crystal on faastRuby♥ #crystaljp

さっちゃん

May 13, 2019
Tweet

More Decks by さっちゃん

Other Decks in Programming

Transcript

  1. λ faastCrystal

    View Slide

  2. .。oO(さっちゃんですよヾ(〃l _ l)ノ゙ ☆)

    View Slide

  3. https://speakerdeck.com/ne_sachirou/faastruby

    View Slide

  4. faastRuby

    View Slide

  5. Visit to the faastRuby Web site. https://faastruby.io/

    View Slide

  6. Serverless Platform for Ruby and Crystal
    https://faastruby.io/

    View Slide

  7. Serverless Platform for Ruby and Crystal

    View Slide

  8. Let's.

    View Slide

  9. faastruby new-project hello --api
    + d ./hello
    + f ./hello/project.yml
    + f ./hello/secrets.yml
    + d ./hello/functions/root
    + f ./hello/functions/root/handler.rb
    + f ./hello/functions/root/faastruby.yml
    + d ./hello/functions/catch-all
    + f ./hello/functions/catch-all/handler.rb
    + f ./hello/functions/catch-all/faastruby.yml
    + d ./hello/public
    + f ./hello/public/faastruby.yml
    + f ./hello/.gitignore
    Initialized empty Git repository in
    ~/hello/.git/
    Project 'hello' initialized.
    Now run:
    $ cd hello
    $ faastruby local
    Then visit http://localhost:3000

    View Slide

  10. mkdir functions/rb

    View Slide

  11. faastruby.yml
    ---
    cli_version: 0.5.25
    name: rb
    runtime: ruby:2.6

    View Slide

  12. handler.rb
    def handler event
    response = {
    'hello' => 'world'
    }
    render json: response
    end

    View Slide

  13. mkdir functions/cr

    View Slide

  14. faastruby.yml
    ---
    cli_version: 0.5.25
    name: cr
    runtime: crystal:0.27.2

    View Slide

  15. handler.cr
    require "json"
    def handler(event)
    response = JSON.build do |json|
    json.object do
    json.field "hello", "world"
    end
    end
    render json: response
    end

    View Slide

  16. faastruby deploy
    ┌ Deploying project 'hello' to workspace 'hello-stage-
    ~'
    ├── [✔] Connecting to workspace 'hello-stage-
    ~'
    ├── [✔] Uploading static assets in 'public'
    ├── [✔] Deploying function from 'functions/rb'
    ├── [✔] Deploying function from 'functions/cr'
    ├── [✔] Deploying function from 'functions/catch-all'
    └── [✔] Deploying function from 'functions/root'
    * Project URL: https://hello-stage-
    ~.
    ~.faast.cloud

    View Slide

  17. $ curl 'https://hello-stage-
    ~.
    ~.faast.cloud/rb'
    {"hello":"world"}
    $ curl 'https://hello-stage-
    ~.
    ~.faast.cloud/cr'
    {"hello":"world"}

    View Slide

  18. Works!
    faast
    faast

    View Slide

  19. Benchmark?

    View Slide

  20. h2load -n 100 -c 1 -t 1 URL
    Ruby
    finished in 20.73s, 4.82 req/s, 1.93KB/s
    requests: 100 total, 100 started, 100 done, 100 succeeded, 0 failed, 0 errored, 0 timeout
    status codes: 100 2xx, 0 3xx, 0 4xx, 0 5xx
    traffic: 39.93KB (40887) total, 32.91KB (33695) headers (space savings 0.00%), 1.66KB (1700) data
    min max mean sd +/- sd
    time for request: 189.23ms 320.82ms 202.13ms 25.53ms 91.00%
    time for connect: 518.60ms 518.60ms 518.60ms 0us 100.00%
    time to 1st byte: 712.13ms 712.13ms 712.13ms 0us 100.00%
    req/s : 4.82 4.82 4.82 0.00 100.00%
    Crystal
    finished in 20.27s, 4.93 req/s, 1.97KB/s
    requests: 100 total, 100 started, 100 done, 100 succeeded, 0 failed, 0 errored, 0 timeout
    status codes: 100 2xx, 0 3xx, 0 4xx, 0 5xx
    traffic: 39.93KB (40887) total, 32.91KB (33695) headers (space savings 0.00%), 1.66KB (1700) data
    min max mean sd +/- sd
    time for request: 182.51ms 404.88ms 197.55ms 39.14ms 94.00%
    time for connect: 513.51ms 513.51ms 513.51ms 0us 100.00%
    time to 1st byte: 699.38ms 699.38ms 699.38ms 0us 100.00%
    req/s : 4.93 4.93 4.93 0.00 100.00%

    View Slide

  21. h2load -n 100 -c 10 -t 10 URL
    Ruby
    finished in 2.78s, 35.98 req/s, 14.51KB/s
    requests: 100 total, 100 started, 100 done, 100 succeeded, 0 failed, 0 errored, 0 timeout
    status codes: 100 2xx, 0 3xx, 0 4xx, 0 5xx
    traffic: 40.33KB (41300) total, 32.91KB (33700) headers (space savings 0.00%), 1.66KB (1700) data
    min max mean sd +/- sd
    time for request: 189.91ms 261.53ms 212.59ms 17.58ms 63.00%
    time for connect: 517.43ms 540.26ms 527.85ms 7.19ms 70.00%
    time to 1st byte: 714.19ms 772.20ms 753.39ms 19.72ms 90.00%
    req/s : 3.60 3.99 3.77 0.12 70.00%
    Crystal
    finished in 2.50s, 39.96 req/s, 16.12KB/s
    requests: 100 total, 100 started, 100 done, 100 succeeded, 0 failed, 0 errored, 0 timeout
    status codes: 100 2xx, 0 3xx, 0 4xx, 0 5xx
    traffic: 40.33KB (41300) total, 32.91KB (33700) headers (space savings 0.00%), 1.66KB (1700) data
    min max mean sd +/- sd
    time for request: 182.24ms 232.80ms 194.89ms 11.66ms 83.00%
    time for connect: 514.20ms 530.94ms 519.75ms 4.58ms 80.00%
    time to 1st byte: 711.84ms 752.36ms 736.42ms 15.44ms 60.00%
    req/s : 4.00 4.18 4.05 0.06 80.00%

    View Slide

  22. Benchmark
    Crystal is a little bit faster than Ruby, but it's not matter.
    They use Nginx. Perhaps the Nginx dose rate limiting.

    View Slide