Skip to content

Async endpoints are much slower compared to equivalent ones written with {plumber}. #61

Open

Description

@joekirincic

Very excited about this package; thanks for all the great work so far. While load testing an app with an async endpoint written with {plumber2}, I noticed unusually low throughput (see summary stats below). When I ran a similar {plumber2} app without async, the performance improved. This is odd because both apps contain a single I/O bound endpoint, so I would expect the async version to have better throughput. For comparison, I ran a third app written with {plumber} instead of {plumber2} that uses {mirai} for async processing. This third app performed better than the synchronous app, which is expected. But the first app and the third app both use {mirai} for async processing, so I'm stumped why the async app written with {plumber2} would be slower.

Summary stats from each load test are as follows. Each load test simulated 200 users with 1-2 seconds between requests for a duration of 1 minute.

load_test min_response_time_ms med_response_time_ms max_response_time_ms total_seconds total_requests rps
plumber2-sync 6.86 465.80 689.46 59.68 5325 89.23
plumber2-async 51.83 8203.13 8600.50 59.20 1130 19.09
plumber-async 3.46 8.82 150.68 59.70 6770 113.40

I've compiled my findings in the repo here. I couldn't think of a better way to package this as a minimally reproducible example, so if the above isn't actionable please let me know and I'll take another stab at it.

The following is the output from sessioninfo::session_info() from inside one of the API containers.

─ Session info ────────────────────────────────────────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.5.1 (2025-06-13)
 os       Ubuntu 24.04.2 LTS
 system   aarch64, linux-gnu
 ui       X11
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       Europe/Berlin
 date     2025-11-08
 pandoc   3.1.3 @ /usr/bin/pandoc
 quarto   NA

─ Packages ────────────────────────────────────────────────────────────────────────────────────────────────────
 package        * version   date (UTC) lib source
 base64enc        0.1-3     2015-07-28 [1] CRAN (R 4.4.1)
 brio             1.1.5     2024-04-24 [1] CRAN (R 4.4.1)
 brotli           1.3.2     2025-03-18 [1] CRAN (R 4.4.2)
 cli              3.6.5     2025-04-23 [1] CRAN (R 4.4.3)
 codetools        0.2-20    2024-03-31 [1] CRAN (R 4.5.1)
 DBI            * 1.2.3     2024-06-02 [1] CRAN (R 4.4.1)
 digest           0.6.37    2024-08-19 [1] CRAN (R 4.4.1)
 evaluate         1.0.5     2025-08-27 [1] CRAN (R 4.4.3)
 fiery            1.3.0     2025-08-20 [1] CRAN (R 4.4.3)
 firesafety       0.1.0     2025-09-10 [1] CRAN (R 4.4.3)
 firestorm        0.1.0     2025-09-01 [1] CRAN (R 4.4.3)
 future           1.67.0    2025-07-29 [1] CRAN (R 4.4.3)
 getopt           1.20.4    2023-10-01 [1] CRAN (R 4.4.1)
 globals          0.18.0    2025-05-08 [1] CRAN (R 4.4.3)
 glue             1.8.0     2024-09-30 [1] CRAN (R 4.4.1)
 httpuv           1.6.16    2025-04-16 [1] CRAN (R 4.4.3)
 jsonlite         2.0.0     2025-03-27 [1] CRAN (R 4.4.2)
 knitr            1.50      2025-03-16 [1] CRAN (R 4.5.1)
 later            1.4.4     2025-08-27 [1] CRAN (R 4.4.3)
 lifecycle        1.0.4     2023-11-07 [1] CRAN (R 4.4.1)
 listenv          0.9.1     2024-01-29 [1] CRAN (R 4.4.1)
 magrittr         2.0.4     2025-09-12 [1] CRAN (R 4.4.3)
 mirai          * 2.5.1     2025-10-06 [1] CRAN (R 4.4.3)
 nanonext         1.7.1     2025-10-01 [1] CRAN (R 4.4.3)
 optparse       * 1.7.5     2024-04-16 [1] CRAN (R 4.4.1)
 otel             0.2.0     2025-08-29 [1] CRAN (R 4.4.3)
 palmerpenguins * 0.1.1     2022-08-15 [1] CRAN (R 4.4.1)
 parallelly       1.45.1    2025-07-24 [1] CRAN (R 4.4.3)
 pillar           1.11.1    2025-09-17 [1] CRAN (R 4.4.3)
 pkgconfig        2.0.3     2019-09-22 [1] CRAN (R 4.4.1)
 plumber        * 1.2.2     2024-03-26 [1] CRAN (R 4.4.1)
 plumber2       * 0.1.0     2025-09-22 [1] CRAN (R 4.4.3)
 promises       * 1.4.0     2025-10-22 [1] CRAN (R 4.4.3)
 purrr            1.1.0     2025-07-10 [1] CRAN (R 4.4.3)
 R6               2.6.1     2025-02-15 [1] CRAN (R 4.5.1)
 ragg             1.5.0     2025-09-02 [1] CRAN (R 4.4.3)
 rapidoc          9.3.4     2023-11-17 [1] CRAN (R 4.4.1)
 Rcpp             1.1.0     2025-07-02 [1] CRAN (R 4.4.3)
 reqres           1.0.0     2025-08-20 [1] CRAN (R 4.4.3)
 rlang            1.1.6     2025-04-11 [1] CRAN (R 4.4.3)
 routr            1.0.0     2025-08-21 [1] CRAN (R 4.4.3)
 roxygen2         7.3.3     2025-09-03 [1] CRAN (R 4.4.3)
 sessioninfo      1.2.3     2025-02-05 [1] CRAN (R 4.4.2)
 sodium           1.4.0     2024-12-16 [1] CRAN (R 4.4.2)
 stringi          1.8.7     2025-03-27 [1] CRAN (R 4.4.3)
 stringr          1.5.2     2025-09-08 [1] CRAN (R 4.4.3)
 svglite          2.2.2     2025-10-21 [1] CRAN (R 4.4.3)
 swagger          5.17.14.1 2024-06-28 [1] CRAN (R 4.4.1)
 systemfonts      1.3.1     2025-10-01 [1] CRAN (R 4.5.1)
 textshaping      1.0.4     2025-10-10 [1] CRAN (R 4.4.3)
 tibble           3.3.0     2025-06-08 [1] CRAN (R 4.4.3)
 triebeard        0.4.1     2023-03-04 [1] CRAN (R 4.4.1)
 urltools         1.7.3.1   2025-06-12 [1] CRAN (R 4.4.3)
 vctrs            0.6.5     2023-12-01 [1] CRAN (R 4.4.1)
 websocket        1.4.4     2025-04-10 [1] CRAN (R 4.4.3)
 webutils         1.2.2     2024-10-04 [1] CRAN (R 4.4.1)
 xfun             0.54      2025-10-30 [1] CRAN (R 4.4.3)
 xml2             1.4.1     2025-10-27 [1] CRAN (R 4.4.3)

 [1] /opt/R/4.5.1/lib/R/library
 * ── Packages attached to the search path.

Activity

  1. thomasp85 commented on Nov 8, 2025

    @thomasp85
    Collaborator

    Thanks for this. I'll dig into it and see if I can find some good explanations and fixes.

  2. thomasp85 commented on Dec 8, 2025

    @thomasp85
    Collaborator

    Can I get you to check with the current dev version. I have done numerous improvements to the performance around the stack so hopefully you should see some improvements

  3. joekirincic commented on Dec 13, 2025

    @joekirincic
    Author

    Excellent! The performance of the async version with {plumber2} is much more competitive now (see table below). It's a little counterintuitive that the synchronous version is now the fastest of the three, but I'm not complaining. I'm cool with closing this issue if you are.

    load_test min_response_time_ms med_response_time_ms max_response_time_ms total_seconds total_requests rps
    plumber2-sync 1.92 4.16 136.61 59.85 6793 113.50
    plumber2-async 4.29 21.25 296.32 59.67 6634 111.18
    plumber-async 2.62 5.67 119.45 59.79 6757 113.01
  4. thomasp85 commented on Dec 16, 2025

    @thomasp85
    Collaborator

    Those are great improvements! I never touched anything related to asynchronous in the latest performance improvement run, so I'm sure there is still something to gain there specifically.

    Would you be willing to add a second plumber2 async measure where you don't use the async tag but rather replicate what happens in the plumber api (handler returns a promise) and post the comparison. For some reason I can't get you docker image to work but I'm sure its a "me" issue

  5. joekirincic commented on Jan 3, 2026

    @joekirincic
    Author

    Happy to. I added the requested implementation (called plumber2-async-manual) and reran the load tests. The results can be found in the table below. I've also included updated output from sessioninfo::session_info() in case that's useful.

    load_test min_response_time_ms med_response_time_ms max_response_time_ms total_seconds total_requests rps
    plumber2-sync 2.40 4.51 77.61 59.88 6793 113.44
    plumber2-async 4.26 12.55 188.59 59.77 6738 112.73
    plumber2-async-manual 4.26 14.93 244.55 59.80 6705 112.12
    plumber-async 3.33 6.50 102.56 59.82 6750 112.84

    The three async apps are still competitive with one another. Surprisingly, plumber2-async-manual was slightly slower than plumber2-async. This holds after several reruns of the load tests. It's surprising because the former app defines the query_penguins function inside of the mirais upfront with the call to mirai::everywhere, so I would expect it to be slightly faster than plumber2-async because it wasn't serializing the query_penguins function during each request. It's also surprising that the plumber-async app still manages to process 45 more requests than plumber2-async-manual because both return a promise in the same manner.

    If there's anything else I can do to help, definitely let me know!

    ─ Session info ───────────────────────────────────────────────────────────────────────────────────────────────────────────
     setting  value
     version  R version 4.5.2 (2025-10-31)
     os       Ubuntu 24.04.3 LTS
     system   aarch64, linux-gnu
     ui       X11
     language (EN)
     collate  en_US.UTF-8
     ctype    en_US.UTF-8
     tz       Europe/Berlin
     date     2026-01-03
     pandoc   3.1.3 @ /usr/bin/pandoc
     quarto   NA
    
    ─ Packages ───────────────────────────────────────────────────────────────────────────────────────────────────────────────
     package     * version    date (UTC) lib source
     askpass       1.2.1      2024-10-04 [1] CRAN (R 4.4.1)
     base64enc     0.1-3      2015-07-28 [1] CRAN (R 4.4.1)
     brio          1.1.5      2024-04-24 [1] CRAN (R 4.4.1)
     brotli        1.3.2      2025-03-18 [1] CRAN (R 4.4.2)
     cli           3.6.5      2025-04-23 [1] CRAN (R 4.4.3)
     crayon        1.5.3      2024-06-20 [1] CRAN (R 4.4.1)
     DBI         * 1.2.3      2024-06-02 [1] CRAN (R 4.4.1)
     evaluate      1.0.5      2025-08-27 [1] CRAN (R 4.4.3)
     fiery         1.4.1.9000 2026-01-03 [1] Github (thomasp85/fiery@8609786)
     fireproof     0.1.0.9000 2026-01-03 [1] Github (thomasp85/fireproof@ef1e245)
     firesafety    0.1.0      2025-09-10 [1] CRAN (R 4.4.3)
     firesale      0.1.1.9000 2026-01-03 [1] Github (thomasp85/firesale@e4e39c2)
     firestorm     0.1.0      2025-09-01 [1] CRAN (R 4.4.3)
     glue          1.8.0      2024-09-30 [1] CRAN (R 4.4.1)
     httpuv        1.6.16     2025-04-16 [1] CRAN (R 4.4.3)
     jose          1.2.1      2024-10-04 [1] CRAN (R 4.4.1)
     jsonlite      2.0.0      2025-03-27 [1] CRAN (R 4.4.2)
     knitr         1.51       2025-12-20 [1] CRAN (R 4.4.3)
     later         1.4.4      2025-08-27 [1] CRAN (R 4.4.3)
     lifecycle     1.0.4      2023-11-07 [1] CRAN (R 4.4.1)
     magrittr      2.0.4      2025-09-12 [1] CRAN (R 4.4.3)
     mirai       * 2.5.3      2025-12-01 [1] CRAN (R 4.4.3)
     nanonext      1.7.2      2025-11-03 [1] CRAN (R 4.4.3)
     openssl       2.3.4      2025-09-30 [1] CRAN (R 4.4.3)
     otel          0.2.0      2025-08-29 [1] CRAN (R 4.4.3)
     plumber     * 1.3.2      2025-12-23 [1] CRAN (R 4.4.3)
     plumber2    * 0.1.1.9000 2026-01-03 [1] Github (posit-dev/plumber2@500c230)
     promises    * 1.5.0      2025-11-01 [1] CRAN (R 4.4.3)
     purrr         1.2.0      2025-11-04 [1] CRAN (R 4.4.3)
     R6            2.6.1      2025-02-15 [1] CRAN (R 4.5.2)
     ragg          1.5.0      2025-09-02 [1] CRAN (R 4.4.3)
     rapidoc       9.3.4      2023-11-17 [1] CRAN (R 4.4.1)
     Rcpp          1.1.0      2025-07-02 [1] CRAN (R 4.4.3)
     reqres        1.2.0.9000 2026-01-03 [1] Github (thomasp85/reqres@cde442a)
     rlang         1.1.6      2025-04-11 [1] CRAN (R 4.4.3)
     routr         2.0.0      2025-12-18 [1] CRAN (R 4.4.3)
     roxygen2      7.3.3      2025-09-03 [1] CRAN (R 4.4.3)
     sessioninfo   1.2.3      2025-02-05 [1] CRAN (R 4.4.2)
     sodium        1.4.0      2024-12-16 [1] CRAN (R 4.4.2)
     storr         1.2.6      2025-04-15 [1] CRAN (R 4.4.3)
     stringi       1.8.7      2025-03-27 [1] CRAN (R 4.4.3)
     stringr       1.6.0      2025-11-04 [1] CRAN (R 4.4.3)
     svglite       2.2.2      2025-10-21 [1] CRAN (R 4.4.3)
     swagger       5.17.14.1  2024-06-28 [1] CRAN (R 4.4.1)
     systemfonts   1.3.1      2025-10-01 [1] CRAN (R 4.5.2)
     textshaping   1.0.4      2025-10-10 [1] CRAN (R 4.4.3)
     triebeard     0.4.1      2023-03-04 [1] CRAN (R 4.4.1)
     urltools      1.7.3.1    2025-06-12 [1] CRAN (R 4.4.3)
     vctrs         0.6.5      2023-12-01 [1] CRAN (R 4.4.1)
     waysign       0.1.0      2025-12-16 [1] CRAN (R 4.4.3)
     websocket     1.4.4      2025-04-10 [1] CRAN (R 4.4.3)
     webutils      1.2.2      2024-10-04 [1] CRAN (R 4.4.1)
     xfun          0.55       2025-12-16 [1] CRAN (R 4.4.3)
     xml2          1.5.1      2025-12-01 [1] CRAN (R 4.4.3)
    
     [1] /opt/R/4.5.2/lib/R/library
     * ── Packages attached to the search path.
    
    ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
    
  6. thomasp85 commented on Jan 13, 2026

    @thomasp85
    Collaborator

    You don't by chance have the distribution of response times at hand? The min, median, and max values would suggest a bigger difference in total_requests than there actually is

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions