simerplaha / SwayDB

Persistent and in-memory key-value storage engine for JVM that scales on a single machine.
https://swaydb.simer.au
Apache License 2.0
293 stars 16 forks source link

Backpressure should be checked after each write #268

Closed simerplaha closed 4 years ago

simerplaha commented 4 years ago

Currently the configuration for blocking back-pressure is applied only when a new file is created. This is not enough as the number of levelZero files build up on each database reboot. Back-pressure should be checked after each write.

The option to log warning should be optional. So I've added logAsWarning to Brake for debugging purposes.

Brake(
  brakeFor = 10.milliseconds,
  releaseRate = 1.millisecond,
  logAsWarning = true
)

The log looks like

20:30:21.430 WARN  BrakePedal - Blocking-backpressure - Braking for: 50 milliseconds.
20:30:21.483 WARN  BrakePedal - Blocking-backpressure - Braking for: 49 milliseconds.
20:30:21.534 WARN  BrakePedal - Blocking-backpressure - Braking for: 48 milliseconds.
20:30:21.587 WARN  BrakePedal - Blocking-backpressure - Braking for: 47 milliseconds.
20:30:21.638 WARN  BrakePedal - Blocking-backpressure - Braking for: 46 milliseconds.
....
...
..
20:30:23.576 WARN  BrakePedal - Blocking-backpressure - Braking for: 3 milliseconds.
20:30:23.580 WARN  BrakePedal - Blocking-backpressure - Braking for: 2 milliseconds.
20:30:23.582 WARN  BrakePedal - Blocking-backpressure - Braking for: 1 millisecond.
20:35:23.970 WARN  BrakePedal - Blocking-backpressure - Brake released!
....
...
..
//starts again if needed
20:35:23.970 WARN  BrakePedal - Blocking-backpressure - Braking for: 50 milliseconds.
20:35:24.023 WARN  BrakePedal - Blocking-backpressure - Braking for: 49 milliseconds.

Block-backpressure is turned off by default because it's blocking. See Accelerator's documentation.