Skip to content

Conversation

crepererum
Copy link
Collaborator

1. refactor: use sync lock in request path

$ env TEST_INTEGRATION=1 KAFKA_CONNECT=localhost:9010 cargo bench --all-features --bench throughput
...

read/rskafka            time:   [7.1591 us 7.2529 us 7.3444 us]
                        change: [-33.377% -22.989% -10.606%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 2 outliers among 15 measurements (13.33%)
  1 (6.67%) high mild
  1 (6.67%) high severe

...

write_sequential/rskafka
                        time:   [335.19 us 347.14 us 366.57 us]
                        change: [-6.1186% +1.7049% +11.034%] (p = 0.71 > 0.05)
                        No change in performance detected.

...

write_parallel/rskafka  time:   [15.904 us 16.063 us 16.261 us]
                        change: [-4.8534% -2.3144% +1.2491%] (p = 0.16 > 0.05)
                        No change in performance detected.
Found 1 outliers among 15 measurements (6.67%)
  1 (6.67%) high severe

2. refactor: avoid thread/task bouncing when sending data

The problem with spawning tasks (or a MPSC construction) is that tokio
will likely execute the task in another thread and requires additional
futex syscalls for synchronization. When sending data we were wrapping
the sending task to prevent cancellation. However cancellation is a
rather unlikely event (unhappy path) and we should only pay for it when
it is really needed.

$ env TEST_INTEGRATION=1 KAFKA_CONNECT=localhost:9010 cargo bench --all-features --bench throughput

...

read/rskafka            time:   [8.9115 us 9.2918 us 9.6791 us]
                        change: [-4.0247% +3.9206% +12.188%] (p = 0.36 > 0.05)
                        No change in performance detected.

write_sequential/rskafka
                        time:   [279.21 us 292.64 us 304.67 us]
                        change: [-21.742% -16.312% -10.823%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 3 outliers among 15 measurements (20.00%)
  1 (6.67%) low severe
  2 (13.33%) low mild

...
write_parallel/rskafka  time:   [15.617 us 15.821 us 16.061 us]
                        change: [-3.4937% +0.0064% +4.3441%] (p = 0.99 > 0.05)
                        No change in performance detected.
Found 1 outliers among 15 measurements (6.67%)
  1 (6.67%) high severe

```console
$ env TEST_INTEGRATION=1 KAFKA_CONNECT=localhost:9010 cargo bench --all-features --bench throughput
...

read/rskafka            time:   [7.1591 us 7.2529 us 7.3444 us]
                        change: [-33.377% -22.989% -10.606%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 2 outliers among 15 measurements (13.33%)
  1 (6.67%) high mild
  1 (6.67%) high severe

...

write_sequential/rskafka
                        time:   [335.19 us 347.14 us 366.57 us]
                        change: [-6.1186% +1.7049% +11.034%] (p = 0.71 > 0.05)
                        No change in performance detected.

...

write_parallel/rskafka  time:   [15.904 us 16.063 us 16.261 us]
                        change: [-4.8534% -2.3144% +1.2491%] (p = 0.16 > 0.05)
                        No change in performance detected.
Found 1 outliers among 15 measurements (6.67%)
  1 (6.67%) high severe
````
The problem with spawning tasks (or a MPSC construction) is that tokio
will likely execute the task in another thread and requires additional
futex syscalls for synchronization. When sending data we were wrapping
the sending task to prevent cancellation. However cancellation is a
rather unlikely event (unhappy path) and we should only pay for it when
it is really needed.

```console
$ env TEST_INTEGRATION=1 KAFKA_CONNECT=localhost:9010 cargo bench --all-features --bench throughput

...

read/rskafka            time:   [8.9115 us 9.2918 us 9.6791 us]
                        change: [-4.0247% +3.9206% +12.188%] (p = 0.36 > 0.05)
                        No change in performance detected.

write_sequential/rskafka
                        time:   [279.21 us 292.64 us 304.67 us]
                        change: [-21.742% -16.312% -10.823%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 3 outliers among 15 measurements (20.00%)
  1 (6.67%) low severe
  2 (13.33%) low mild

...
write_parallel/rskafka  time:   [15.617 us 15.821 us 16.061 us]
                        change: [-3.4937% +0.0064% +4.3441%] (p = 0.99 > 0.05)
                        No change in performance detected.
Found 1 outliers among 15 measurements (6.67%)
  1 (6.67%) high severe
```
@crepererum crepererum requested a review from tustvold July 21, 2022 05:58
@crepererum crepererum added the automerge Instruct kodiak to merge the PR label Jul 21, 2022
@kodiakhq kodiakhq bot merged commit 1ca7c47 into main Jul 21, 2022
@kodiakhq kodiakhq bot deleted the crepererum/speed_up_io branch July 21, 2022 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Instruct kodiak to merge the PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants