Websocket memory usage

This page summarizes the projects mentioned and recommended in the original post on /r/golang

Our great sponsors
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • SaaSHub - Software Alternatives and Reviews
  • nbio

    Pure Go 1000k+ connections solution, support tls/http1.x/websocket and basically compatible with net/http, with high-performance and low memory cost, non-blocking, event-driven, easy-to-use.

  • There is also https://github.com/lesismal/nbio library which also implements somewhat similar to https://github.com/gobwas/ws - but with async websocket frame parser. Also shifts you from STD lib.

  • websocket

    Discontinued A fast, well-tested and widely used WebSocket implementation for Go.

  • What I can say is that if you will use Gorilla Websocket (https://github.com/gorilla/websocket) (it's archived now unfortunately, but still super robust) - then you can go to sth like 15-20kb per connection - see https://github.com/FZambia/go_websocket_memory - to achieve this you need to reduce read buffer size, reuse write buffers, use goroutine after hijacking connection (following chat example in Gorilla WebSocket repo).

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
  • go_websocket_memory

    Investigate Gorilla Websocket memory usage in various scenarios

  • What I can say is that if you will use Gorilla Websocket (https://github.com/gorilla/websocket) (it's archived now unfortunately, but still super robust) - then you can go to sth like 15-20kb per connection - see https://github.com/FZambia/go_websocket_memory - to achieve this you need to reduce read buffer size, reuse write buffers, use goroutine after hijacking connection (following chat example in Gorilla WebSocket repo).

  • ws

    Tiny WebSocket library for Go. (by gobwas)

  • Then take a look at this article - https://www.freecodecamp.org/news/million-websockets-and-go-cc58418460bb/ - using external from Go std lib epoll implementation and https://github.com/gobwas/ws lib it's possible to reduce memory usage per connection drastically. Though keep in mind that this approach is not obvious to implement right and you better to go with STD lib.

  • websocket

    Minimal and idiomatic WebSocket library for Go (by nhooyr)

  • Also take a look at https://github.com/nhooyr/websocket - which is a good ws library, but I don't have anything specific about its memory usage per connection. But from what I see it will be somewhat similar to x/net/websocket.

  • centrifuge

    Real-time messaging library for Go. The simplest way to add feature-rich and scalable WebSocket support to your application. The core of Centrifugo server.

  • There are libraries which provide more advanced APIs for creating real-time applications, for example https://github.com/centrifugal/centrifuge

  • go

    The Go programming language

  • Would be great to have the ideas from nbio and gobwas/ws in standard library at some point. Because I personally worry to shift from std lib. Custom TLS implementation makes me nervous, things like QUIC will be not available when I decide I need them in the application, etc. Unfortunately seems that discussions which could make it happen (like this one https://github.com/golang/go/issues/15735) not proceeding these days.

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts