actix / actix/actix-web

Peak memory consumption turns into the overall memory consumption for the whole connection

Abierto
#2,075 0 comentarios 10 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Rust
Estrellas
24.8k
Forks
1.9k
Merge medio
23 h 10 min
PR fusionados (30 d)
26

Descripción

I believe this is a known issue, but I'm opening this to track possible solutions.

The most probable cause is that `BytesMut` tries very hard to not do more allocations than necessary, so it will try to hold the underlying buffer indefinitely even if the buffer is way bigger than necessary. The dispatcher does several splits on the `BytesMut`, but they're usually dropped before a new `reserve` on the next message, because of that, the dispatcher's `BytesMut` will mostly remain unique during `reserve` calls, which will cause it to remain holding the large buffer.

This affects badly long lived websocket connections.

## Expected Behavior
Peak memory consumption should be temporary.

## Current Behavior
Memory consumption only increases during connection, peak consumption turns into the overall consumption.

## Possible Solution
Have a size threshold, that when crossed could cause the dispatcher to create a new `BytesMut` when the old is completely drained/parsed. Ideally, this threshold should be user configurable.

## Steps to Reproduce (for bugs)
1. Create a websocket server.
2. Establish a connection and make the client send small payloads, less than 8kB (default size of the `BytesMut` in the dispatcher).
3. Send bigger payloads, eg. 16kB.
4. Go back to sending smaller payloads.
5. Track memory consumption.

Example application (red peaks are caused by payload handling and processing):
![mixed](https://user-images.githubusercontent.com/46510852/111089257-ccacab00-8509-11eb-9abe-6b6414681033.png)

* Actix Web Version: 4-beta.4

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.