Skip to content

Memory usage increases with disk latency – potential backpressure improvement? #259

Closed
@apuig

Description

@apuig

Hi there!

First of all, kudos on the great work with this library, it's really clever how you've architected the message durability and decoupled it from the upload mechanism. very nice.

While experimenting with the library (I'm relatively new to Kotlin), I noticed the use of trySend in Channel(UNLIMITED), which caught my attention. It made me wonder whether high disk latency could lead to unintended memory growth. We're evaluating to use this library on server environments, where we can't necessarily expect the same I/O performance as on Android devices, especially in virtualized environments or network-attached storage. Disk latency in these setups can be quite variable and could become a bottleneck.

To explore this, I prepared a test scenario where:

  • Events are written at a sustained rate.
  • Initially, the HTTP endpoint is down
  • After a short period, the endpoint begins to accept requests again.

Here’s a link to the test setup:
https://github.com/apuig/segmentio-analytics-kotlin

Is your feature request related to a problem? Please describe.
Under the scenario above, I've observed that memory usage increases significantly if disk I/O is slow, leading to unmanaged growth as events accumulate.

Describe the solution you'd like
Introduce a mechanism or configuration option to limit memory usage when backpressure builds due to slow disk writes.

Describe alternatives you've considered
I attempted to use a bounded dispatcher by providing a custom CoroutineConfiguration with a limited FileIODispatcher, but the memory usage growth persisted. I suspect there are other channels involved.

Thanks for taking the time to consider this!

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions