This project contains a small Seastar program and minimal cmake scaffolding. The example contains both coroutines and continuation passing style uses of Seastar.
Install dependencies (assuming a recent verison of Ubuntu such as 22.04):
git submodule update --init --recursive
seastar/install-dependencies.sh
apt-get install -qq ninja-build clang
Configure and build:
CXX=clang++ CC=clang cmake -Bbuild -S. -GNinja
ninja -C build
The sample program splits an input file into chunks. Each core reads a subset of the input file into memory and then writes this subset out to a new file. The size of the per-core subset may be larger than memory, in which case more than one subset per core will be generated.
First, generate some data. This command will generate around 200mb of data.
dd if=/dev/zero of=input.dat bs=4096 count=50000
Next, invoke the program. Here we limit the total system memory to 500 MB, use 5 cores, and then we further limit memory to 1% of the amount available on each core. Each command line argument is optional except the input file. If the amount of memory or the number of cores are not specified then the program will try to use all of the resources available.
$ ./main --input input.dat -m500 -c5 --memory-pct 1.0
The program should output a summary on each core about the data it is responsible for, and then once per second a per-core progress is printed.
INFO 2024-01-13 13:10:14,214 [shard 0] splitter - Processing 10000 pages with index 0 to 9999
INFO 2024-01-13 13:10:14,214 [shard 1] splitter - Processing 10000 pages with index 10000 to 19999
INFO 2024-01-13 13:10:14,214 [shard 3] splitter - Processing 10000 pages with index 30000 to 39999
INFO 2024-01-13 13:10:14,214 [shard 2] splitter - Processing 10000 pages with index 20000 to 29999
INFO 2024-01-13 13:10:14,214 [shard 4] splitter - Processing 10000 pages with index 40000 to 49999
INFO 2024-01-13 13:10:14,214 [shard 0] splitter - Progress: 0.0 0.0 0.0 0.0 0.0
INFO 2024-01-13 13:10:15,214 [shard 0] splitter - Progress: 54.5 54.3 55.2 53.8 53.6
INFO 2024-01-13 13:10:16,215 [shard 0] splitter - Progress: 100.0 100.0 100.0 100.0 100.0
After the program exists there should be a number of chunk files on disk. The
chunk file format is chunk.<core-id>.<chunk-id>
.
$ ls -l chunk*
-rw-r--r--. 1 user user 331776 Jan 13 13:10 chunk.core-0.0
-rw-r--r--. 1 user user 331776 Jan 13 13:10 chunk.core-0.1
-rw-r--r--. 1 user user 331776 Jan 13 13:10 chunk.core-0.10
-rw-r--r--. 1 user user 331776 Jan 13 13:10 chunk.core-0.100
-rw-r--r--. 1 user user 331776 Jan 13 13:10 chunk.core-0.101
-rw-r--r--. 1 user user 331776 Jan 13 13:10 chunk.core-0.102
-rw-r--r--. 1 user user 331776 Jan 13 13:10 chunk.core-0.103
- The Seastar tutorial
- ScyllaDB is a large project that uses Seastar.
- CMake tutorial
This project uses a GitHub action to run the same set of instructions as above. Please see .github/workflows/build.yml for reference.