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

[PERF] Experiment with backend websocket #5367

Closed
chibenwa opened this issue Dec 9, 2024 · 1 comment
Closed

[PERF] Experiment with backend websocket #5367

chibenwa opened this issue Dec 9, 2024 · 1 comment
Assignees
Labels
perf Contributes some performance enhencements

Comments

@chibenwa
Copy link
Member

chibenwa commented Dec 9, 2024

Why ?

CF linagora/tmail-flutter#3331

Screenshot from 2024-12-09 17-40-55

That's a lot of Echo request, I am unsure of the generated system load... I'd rather try to switch it to a less impactful mechanism.

How?

Cf chatGPT

public class WebSocketServer {
    public static void main(String[] args) {
        HttpServer.create()
                .port(8080) // Port d'écoute du serveur
                .route(routes -> routes.ws("/ws", WebSocketServer::handleWebSocket))
                .bindNow()
                .onDispose()
                .block();
    }

    private static Mono<Void> handleWebSocket(WebsocketInbound inbound, WebsocketOutbound outbound) {
        // Gestion des messages reçus
        Flux<String> inboundMessages = inbound.receive()
                .asString()
                .doOnNext(message -> System.out.println("Message reçu : " + message));

        // Envoi périodique de pings au client
        Flux<WebSocketFrame> pings = Flux.interval(Duration.ofSeconds(10)) // Ping toutes les 10 secondes
                .map(i -> new PingWebSocketFrame(Unpooled.copiedBuffer("ping", StandardCharsets.UTF_8)))
                .doOnNext(frame -> System.out.println("Envoi d'un ping au client"));

        // Flux combiné : traiter les messages entrants et envoyer des pings
        return outbound.send(pings)
                .mergeWith(inboundMessages.then()) // Continue d'écouter les messages entrants
                .then();
    }
}

Validate that it is enough to maintain a websocket connection opened through Apisix + Nginx

Add in jmap.properties the following configutration values:

websocket.ping.interval=30s

If not specified then defaults to no ping!

@chibenwa chibenwa added the perf Contributes some performance enhencements label Dec 9, 2024
@vttranlina
Copy link
Member

pr apache#2561

@Arsnael Arsnael closed this as completed Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf Contributes some performance enhencements
Projects
None yet
Development

No branches or pull requests

3 participants