Three, functionally similar web services, written in Java, Go, and Rust.
The main motivation for writing these three simple web services, is to compare the three languages, Java, Go, and Rust.
Route | Request example | Response example |
---|---|---|
GET /hello | /hello | {"message":"Hello, World"} |
GET /greeting/{name} | /greeting/Jane | {"greeting":"Hello, Jane!"} |
GET /fibonacci/{number} | /fibonacci/45 | {"input":45,"output":1134903170} |
For each version of the program, issue the commands from the specific language folder.
mvn package
The compiled program (executable jar) should now be in the ws-compare/java/target
folder:
webservice.jar
java -jar target/webservice.jar
go build -o webservice
The compiled program should now be in the ws-compare/go
folder:
webservice
./webservice
cargo build --release
The compiled program should be in ws-compare/rust/target/release
folder:
webservice
./webservice
For example, using curl:
curl http://localhost:8080/fibonacci/20
The response should be:
{"input":20,"output":75025}
Using wrk
Default timeout (2 seconds)
wrk -t2 -c400 -d30s http://127.0.0.1:8080/fibonacci/25
Extended timeout (5 seconds)
wrk -t2 -c400 -d30s http://127.0.0.1:8080/fibonacci/25 --timeout 5
Using vegeta
Run for 30 seconds, 2 workers, no rate limiting
echo "GET http://localhost:8080/fibonacci/25" | vegeta attack -duration=30s -rate=0 -max-workers=2 | tee results.bin | vegeta report
Generate graph
vegeta plot > plot.html
Example: while in the java directory, run the command:
docker build -t java/webservice:1.0 .
docker run -p 8080:8080 java/webservice:1.0
- The code is not suitable for production use. And is not idiomatic to each language. Also, lacks tests and documentation.
- This project was written to compare some metrics using different programming languages. The metrics I was looking for:
- Compiled artifact size
- Size in memory while running idle
- Size in memory while running at peak requests per second
- Requests per second, latency, and timeouts
- Packaged, deployment ready build with the relevant runtime. (Docker image)
- Compile/build time