Skip to content
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

feat: switch from Cowboy to Bandit, upgrade to Phoenix 1.7 #678

Merged
merged 10 commits into from
Oct 4, 2023

Conversation

paulswartz
Copy link
Member

@paulswartz paulswartz commented Oct 2, 2023

Bandit is a new web server, designed around supporting the Plug interface that Phoenix uses.

It also logs errors much more aggressively, which Phoenix 1.7 handles much better than Phoenix 1.6.

Best to review this commit-by-commit: the reformatting commit adds a bit of noise.

Formatting has moved into the "Dev" tasks, as it now depends on the compiled dependencies. I'll remove it from the requirements when this merges.

Copy link
Contributor

@nlwstein nlwstein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it would be worth it to (have you already?) load test this module vs. Cowboy - I'm not opposed to just throwing it into production and reverting if necessary but it might be interesting to see how much extra stability / performance we can get out of it in a synthetic test too.

Specifically, # of concurrent connections per instance would be very interesting given the issue last week.

My only q w/ what's here is the http_1_options - I assume that was added for a reason so I just wanted to make sure we wouldn't benefit from the compression on HTTP2 as well.

apps/api_web/config/config.exs Show resolved Hide resolved
@paulswartz paulswartz temporarily deployed to dev-blue October 3, 2023 13:22 — with GitHub Actions Inactive
@paulswartz
Copy link
Member Author

@nlwstein I'm throwing it back up on dev-blue for further testing.

When I was testing it last night, I was able to get it up to around 1,000 /vehicle streams per server before I saw AWS scale up the number of instances.

@paulswartz paulswartz temporarily deployed to dev-blue October 3, 2023 13:32 — with GitHub Actions Inactive
[Bandit](https://hexdocs.pm/bandit/Bandit.html) is a new web server,
designed around supporting the Plug interface that Phoenix uses.
@paulswartz paulswartz temporarily deployed to dev-blue October 3, 2023 15:07 — with GitHub Actions Inactive
@paulswartz paulswartz temporarily deployed to dev-green October 3, 2023 15:14 — with GitHub Actions Inactive
@paulswartz
Copy link
Member Author

@nlwstein doing some further testing:

  • I can have 2,000 open connections without appreciably increasing the memory or CPU usage on dev-blue
  • dev-green gets more traffic than dev (not sure why) but it's using 40% of the CPU and a bit less memory

I'd be okay with doing a temporary deploy to api-prod to see what it looks like with even more traffic, but I'll leave that up to you and @bklebe.

@bklebe
Copy link
Contributor

bklebe commented Oct 3, 2023

I support trying a prod deploy. Maybe do it from this branch though so we can revert it easily?

@paulswartz paulswartz temporarily deployed to dev-green October 3, 2023 23:49 — with GitHub Actions Inactive
@paulswartz paulswartz temporarily deployed to dev-green October 3, 2023 23:56 — with GitHub Actions Inactive
@paulswartz paulswartz force-pushed the ps-bandit branch 2 times, most recently from a484d8c to 2e9c096 Compare October 4, 2023 00:09
@paulswartz paulswartz changed the title feat: switch from Cowboy to bandit feat: switch from Cowboy to Bandit, upgrade to Phoenix 1.7 Oct 4, 2023
@paulswartz paulswartz temporarily deployed to dev-green October 4, 2023 00:40 — with GitHub Actions Inactive
@paulswartz
Copy link
Member Author

So I went down a bit of a rabbit hole on this one looking into the various errors. It turns out that this was a known issue with how Bandit logs errors coming from Phoenix (see phoenixframework/phoenix#5445 for more), so Phoenix needed to be upgraded in order to address the errors. There were quite a few changes in Phoenix between 1.6 and 1.7, so the upgrade was a bit more involved than simply bumping the version in the mix.exs file.

All that being said: I'll run this on dev-green overnight to make sure there aren't any other unexpected issues, and then maybe we can try it on production again?

@paulswartz paulswartz temporarily deployed to dev-green October 4, 2023 00:49 — with GitHub Actions Inactive
@paulswartz paulswartz temporarily deployed to dev-green October 4, 2023 01:07 — with GitHub Actions Inactive
@github-actions
Copy link

github-actions bot commented Oct 4, 2023

Coverage of commit 683518e

Summary coverage rate:
  lines......: 89.2% (4098 of 4592 lines)
  functions..: 70.9% (2225 of 3139 functions)
  branches...: no data found

Files changed coverage rate:
                                                                        |Lines       |Functions  |Branches    
  Filename                                                              |Rate     Num|Rate    Num|Rate     Num
  ============================================================================================================
  apps/api_web/lib/api_web/event_stream.ex                              |83.0%     47|84.6%    13|    -      0
  apps/api_web/lib/api_web/event_stream/supervisor.ex                   |85.7%     14| 100%     7|    -      0
  apps/api_web/lib/api_web/router.ex                                    |92.3%     52|58.0%   157|    -      0
  apps/api_web/lib/api_web/swagger_helpers.ex                           |98.9%     95| 100%    35|    -      0
  apps/api_web/lib/api_web/view_helpers.ex                              |83.3%      6|50.0%     2|    -      0
  apps/api_web/lib/api_web/views/error_helpers.ex                       | 100%      7| 100%     3|    -      0
  apps/api_web/lib/api_web/views/route_view.ex                          |85.7%     21|37.0%    46|    -      0
  apps/api_web/lib/api_web/views/stop_view.ex                           | 100%     28|84.2%    57|    -      0
  apps/api_web/lib/api_web/web.ex                                       | 0.0%      1| 0.0%     6|    -      0

Download coverage report

@paulswartz paulswartz temporarily deployed to prod October 4, 2023 14:38 — with GitHub Actions Inactive
@paulswartz paulswartz temporarily deployed to dev-green October 4, 2023 14:49 — with GitHub Actions Inactive
@mbta mbta deleted a comment from github-actions bot Oct 4, 2023
@mbta mbta deleted a comment from github-actions bot Oct 4, 2023
@mbta mbta deleted a comment from github-actions bot Oct 4, 2023
@github-actions
Copy link

github-actions bot commented Oct 4, 2023

Coverage of commit f84d158

Summary coverage rate:
  lines......: 89.3% (4102 of 4595 lines)
  functions..: 70.9% (2225 of 3139 functions)
  branches...: no data found

Files changed coverage rate:
                                                                        |Lines       |Functions  |Branches    
  Filename                                                              |Rate     Num|Rate    Num|Rate     Num
  ============================================================================================================
  apps/api_web/lib/api_web/event_stream.ex                              |84.0%     50|84.6%    13|    -      0
  apps/api_web/lib/api_web/event_stream/supervisor.ex                   |85.7%     14| 100%     7|    -      0
  apps/api_web/lib/api_web/router.ex                                    |92.3%     52|58.0%   157|    -      0
  apps/api_web/lib/api_web/swagger_helpers.ex                           |98.9%     95| 100%    35|    -      0
  apps/api_web/lib/api_web/view_helpers.ex                              |83.3%      6|50.0%     2|    -      0
  apps/api_web/lib/api_web/views/error_helpers.ex                       | 100%      7| 100%     3|    -      0
  apps/api_web/lib/api_web/views/route_view.ex                          |85.7%     21|37.0%    46|    -      0
  apps/api_web/lib/api_web/views/stop_view.ex                           | 100%     28|84.2%    57|    -      0
  apps/api_web/lib/api_web/web.ex                                       | 0.0%      1| 0.0%     6|    -      0

Download coverage report

@paulswartz paulswartz requested review from nlwstein and removed request for nlwstein October 4, 2023 18:10
@paulswartz paulswartz merged commit bc50cf8 into master Oct 4, 2023
7 checks passed
@paulswartz paulswartz deleted the ps-bandit branch October 5, 2023 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants