https://github.com/simlay/line-server-exercise
https://github.com/simlay/line-server-exercise
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/simlay/line-server-exercise
- Owner: simlay
- License: apache-2.0
- Created: 2023-06-02T21:11:35.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-07-17T05:37:23.000Z (almost 2 years ago)
- Last Synced: 2025-12-29T04:18:29.142Z (6 months ago)
- Language: Rust
- Size: 174 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://codecov.io/gh/simlay/line-server-exercise)
[](https://github.com/simlay/line-server-exercise/actions/workflows/security-audit.yml)
[](https://github.com/simlay/line-server-exercise/actions/workflows/ci.yml)
# Intro
See [PROPMT.md](./PROMPT.md) for the exact description of this exercise.
# Additions
* The Specification said that any error should return `ERR\r\n`. I felt that
this was not descriptive enough and so the responses for Errors are more human
readable.
- In the event of an known command, `Err - THIS_COMMAND_DOES_NOT_EXIST is an invalid command. \`GET nnnn | QUIT | SHUTDOWN\` are valid commands.\r\n`
- In the event that the `GET nnnn` command is out of bounds for the number of lines in the input text, something like `Err - failed to retrieve line 1000. There are only 4 lines available.\r\n`
- In the event that the `GET nnnn` has an unparsible `usize` digit or is not a digit something like `Err - invalid digit found in string. Is AOEU an unsigned integer or under usize::MAX?\r\n` will be returned.
# Requirements
To run this you'll need [the rust
toolchain](https://www.rust-lang.org/tools/install) and either `socat` (my
recommendation), `netcat` or maybe `telnet`.
# Usage
In one terminal run:
```bash
cargo run -- --line-file ./example.txt
```
In another terminal run:
```bash
socat STDIO TCP4:localhost:10497
```
In the 2nd terminal type on of:
* `GET 1`
* `QUIT`
* `SHUTDOWN`
# Questions and Answers
Q: How does your system work? (if not addressed in comments in source)
* This system reads in a file line by line, then shares that `Vec`
across multiple tokio green threeds for each local connection
Q: How will your system perform as the number of requests per second increases?
* Right now this is system uses the default tokio thread setup. This should
scale well with new clients and requests per second.
Q: How will your system perform with a 1 GB file? a 100 GB file? a 1,000 GB file?
* This system was not designed to optimize for a reduced memory footprint. It
was designed to handle many clients simultaneously.
Q: What documentation, websites, papers, etc did you consult in doing this assignment?
* [`tokio::select`](https://tokio.rs/tokio/tutorial/select) and other tokio objects.
Q: What third-party libraries or other tools does the system use?
* [tokio](https://crates.io/crates/tokio)
* [log](https://crates.io/crates/log)
* [env_logger](https://crates.io/crates/env_logger)
* [anyhow](https://crates.io/crates/anyhow)
* [clap](https://crates.io/crates/clap)
* [pretty_assertions](https://crates.io/crates/pretty_assertions)
Q: How long did you spend on this exercise?
* ~3 hours.
# Future work
Given that this is purely an exercise, I elected not to build out too many
features. I played around with using
[criterion](https://bheisler.github.io/criterion.rs/book/getting_started.html)
to use of `cargo bench` but found the tooling a bit more complicated than I
wanted for this project.
This application looks to just be using one core. There is a
`one_hundred_clients` test where there are 100 clients requesting 400 lines of
a `40000` line file with little addition to CI runtime.