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

Replace mongoose with Boost ASIO and support keep alive connections #240

Merged
merged 3 commits into from
Jun 4, 2024

Conversation

edubart
Copy link
Contributor

@edubart edubart commented May 13, 2024

Implementation details:

  • The client uses synchronous IO.
  • In the client, special care is taken when connect/write/read calls are interrupted, so the client does not lose track of spawned remote machines, otherwise it could leave dead zombies when its process receives SIGTERM/SIGINT.
  • The client persist connections with keep alive, so we speed up request throughput
  • The client still use SO_LINGER option to minimize TIME_WAIT connections during fork
  • Both client and server uses TCP_NODELAY to minimize connection latency
  • The server uses asynchronous IO, so we can supporting connecting multiple clients in parallel and forking them.
  • The server only shut downs when all asynchronous operations are either completed or cancelled. Meaning SIGTERM will not make it close right-away, it will only gracefully terminate when all clients sessions are gracefully closed by the client.
  • In the server, special care is taken during the fork.
  • Server uses SO_REUSEADDR flag
  • I've opted to disable threads, EPOLL and EVENTFD, to force Boost ASIO use select() based implementation, so we have less chance of issues with fork().
  • Boost ASIO was used for networking
  • Boost Beast was used for parsing HTTP requests/responses
  • There is no need to link any library, only header-only libraries from Boost were used.
  • Nlohmann JSON library was bundled in third party
  • make dep and make downloads were removed
  • I did some stress tests on the changes, ran thousands of requests/forks per second, found no issue so far.
  • All mongoose related code was removed.

This replaces:

This should close:

@edubart edubart added the enhancement New feature or request label May 13, 2024
@edubart edubart added this to the v0.18.0 milestone May 13, 2024
@edubart edubart self-assigned this May 13, 2024
@edubart edubart changed the title refactor: use Boost ASIO instead of mongoose for TCP connections Replace mongoose with Boost ASIO and support keep alive connections May 13, 2024
@edubart edubart linked an issue May 13, 2024 that may be closed by this pull request
@edubart edubart force-pushed the refactor/boost-asio branch 4 times, most recently from 34567cb to da8fdd5 Compare May 21, 2024 17:17
@edubart edubart requested a review from diegonehab May 27, 2024 19:48
@edubart edubart marked this pull request as ready for review May 27, 2024 19:48
@edubart edubart requested a review from a team May 27, 2024 19:49
Copy link
Contributor

@diegonehab diegonehab left a comment

Choose a reason for hiding this comment

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

This is looking good.

@edubart edubart force-pushed the refactor/boost-asio branch 2 times, most recently from 0472704 to f3854ad Compare May 31, 2024 16:11
@edubart edubart requested a review from diegonehab May 31, 2024 18:26
@edubart edubart requested a review from a team June 3, 2024 15:01
@edubart edubart merged commit dfaff6b into main Jun 4, 2024
8 checks passed
@edubart edubart deleted the refactor/boost-asio branch June 4, 2024 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
3 participants