ndragazis / tinykv

Simple key value store based on Seastar
Apache License 2.0
0 stars 0 forks source link

[http-server] Create an HTTP server with Seastar #3

Open ndragazis opened 1 week ago

ndragazis commented 1 week ago

The goal is to create a kv store that presents an HTTP REST API and uses the Seastar framework. What primitives does Seastar provide to create an HTTP server?

ndragazis commented 1 week ago

Let's start from the httpd application in the Seastar repo: https://github.com/scylladb/seastar/blob/master/apps/httpd/main.cc

The server utilizes the http library. The interface lives in include/seastar/http/httpd.hh. Main objects:

I notice that the httpd application spawns the http_server object inside a Seastar thread (see seastar::async()). However, the assignment recommends using Seastar coroutines.

ndragazis commented 1 week ago

Seastar Threads vs Coroutines

Coroutines require C++20 and a supporting compiler. The Dockerfile installs g++ 13.2.1. This does support C++20, however, we have to add the flag -std=c++20 in CFLAGS.

Documentation for Seastar Threads: https://github.com/scylladb/seastar/blob/master/doc/tutorial.md#seastarthread Documentation for Seastar Coroutines: https://github.com/scylladb/seastar/blob/master/doc/tutorial.md#coroutines

My understanding is that they both provide a synchronous programming model (unlike futures and promises), and they differ on how they implement blocking behavior.

So, coroutines scale better than threads since they consume less memory, but threads run faster than a long sequence of nested coroutines, since each coroutine call would require a heap allocation request.