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

Parser improvements #5

Merged
merged 10 commits into from
Jun 16, 2023
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ To e.g. turn the VNS server off, build with
cargo run --release --no-default-features # --features alpha,vnc to explicitly enable
```

## Usage of SIMD and nightly Rust
[Fabian Wunsch](https://github.com/fabi321) has introduced initial support for SIMD when parsing the hexadecimal color values in [#5](https://github.com/sbernauer/breakwater/pull/5). Thanks!
We might be able to extend the support, parsing the decimal coordinates or blending colors using alpha using SIMD would be awesome as well. PRs welcome!

As `portable_simd` is a unstable feature, we configured this project to use nightly Rust in `rust-toolchain.toml`. Once the feature is stable we can switch back to stable Rust.

If the SIMD or nightly part causes any problems on your setup please reach out by [creating an Issue](https://github.com/sbernauer/breakwater/issues/new)!

# Run in docker container
This command will start the Pixelflut server in a docker container
```bash
Expand Down Expand Up @@ -131,6 +139,9 @@ If you visit the Grafana server (user=admin, password=admin) you will have acces
![Grafana screenshot](docs/images/Screenshot_20220210_215752.png)

# Performance

:warning: The figures below are outdated. The performance of breakwater has increased significant in the meantime. I sadly don't have access to the server any more to run the benchmarks - happy about any figures for a beefy system. At GPN 21 we were able to reach 80 Gbit/s (40 via network and 40 via loopback) on a 20 core/40 thread system while serving > 500 connections :)

## Laptop
My Laptop has a `Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz` (6 Cores/12 Threads) and 2 DDR4 RAM modules with 16 GB each and 2667 MT/s.
The Pixelflut-server and Pixelflut-client [Sturmflut](https://github.com/TobleMiner/sturmflut) both run on my Laptop using 24 connections.
Expand All @@ -149,7 +160,6 @@ The server has two `Intel(R) Xeon(R) CPU E5-2660 v2 @ 2.20GHz` processors with 1
Another server was used as a Pixelflut-client [Sturmflut](https://github.com/TobleMiner/sturmflut).
The servers were connected with two 40G and one 10G links, through which traffic was generated.


| Server | Language | Sustainable traffic |
|-------------------------------------------------------|----------|---------------------|
| [Shoreline](https://github.com/TobleMiner/shoreline) | C | 34 Gbit/s |
Expand Down
49 changes: 1 addition & 48 deletions benches/benchmarks.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use breakwater::{
framebuffer::FrameBuffer,
parser::{from_hex_char_lookup, from_hex_char_map, parse_pixelflut_commands, ParserState},
parser::{parse_pixelflut_commands, ParserState},
test::helpers::{get_commands_to_draw_rect, DevNullTcpStream},
};
use criterion::{
Expand All @@ -20,46 +20,6 @@ async fn invoke_parse_pixelflut_commands(
parse_pixelflut_commands(input, fb, &mut stream, parser_state).await;
}

#[allow(unused)] // Benchmarks are commented out by default
fn invoke_from_hex_char_map() -> u8 {
// So that we actually compute something
let mut result = 0;
for char in b'0'..=b'9' {
result |= from_hex_char_map(char);
}
for char in b'a'..=b'f' {
result |= from_hex_char_map(char);
}
for char in b'A'..=b'F' {
result |= from_hex_char_map(char);
}
result |= from_hex_char_map(b'\n');
result |= from_hex_char_map(b' ');
result |= from_hex_char_map(b';');
result |= from_hex_char_map(b'%');
result
}

#[allow(unused)] // Benchmarks are commented out by default
fn invoke_from_hex_char_lookup() -> u8 {
// So that we actually compute something
let mut result = 0;
for char in b'0'..=b'9' {
result |= from_hex_char_lookup(char);
}
for char in b'a'..=b'f' {
result |= from_hex_char_lookup(char);
}
for char in b'A'..=b'F' {
result |= from_hex_char_lookup(char);
}
result |= from_hex_char_lookup(b'\n');
result |= from_hex_char_lookup(b' ');
result |= from_hex_char_lookup(b';');
result |= from_hex_char_lookup(b'%');
result
}

fn from_elem(c: &mut Criterion) {
let draw_commands = get_commands_to_draw_rect(FRAMEBUFFER_WIDTH, FRAMEBUFFER_HEIGHT, 0x123456);
let draw_commands = draw_commands.as_bytes();
Expand Down Expand Up @@ -94,13 +54,6 @@ fn from_elem(c: &mut Criterion) {
// .iter(|| invoke_parse_pixelflut_commands(input, &fb, parser_state.clone()));
// },
// );

// c.bench_function("from_hex_char_map", |b: &mut criterion::Bencher| {
// b.iter(invoke_from_hex_char_map)
// });
// c.bench_function("from_hex_char_lookup", |b: &mut criterion::Bencher| {
// b.iter(invoke_from_hex_char_lookup)
// });
}

criterion_group!(
Expand Down
2 changes: 2 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[toolchain]
channel = "nightly"
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![feature(portable_simd)]

pub mod args;
pub mod framebuffer;
pub mod network;
Expand Down
16 changes: 16 additions & 0 deletions src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,22 @@ mod test {
assert_eq!(expected, stream.get_output());
}

#[rstest]
#[case("PX 0 0 aaaaaa\n")]
#[case("PX 0 0 aa\n")]
#[tokio::test]
async fn test_safe(
#[case] input: &str,
ip: IpAddr,
fb: Arc<FrameBuffer>,
statistics_channel: (Sender<StatisticsEvent>, Receiver<StatisticsEvent>),
) {
let mut stream = MockTcpStream::from_input(input);
handle_connection(&mut stream, ip, fb.clone(), statistics_channel.0).await;
// Test if it panics
assert_eq!(fb.get(0, 0).unwrap() & 0x00ff_ffff, 0xaaaaaa);
}

#[rstest]
#[case(5, 5, 0, 0)]
#[case(6, 6, 0, 0)]
Expand Down
Loading
Loading