* MM-21012: Revamp websocket implementation We replace the old gorilla/websocket implementation with the gobwas/ws library. The gorilla library was in maintenance mode and had a high level API due to which we cannot use that for situations where a large number of concurrent connections needs to be supported. The ws library is a very low-level library that allows us to work with raw net.Conns. We make several improvements: - We completely remove the reader goroutines, and instead replace them with a manual epoll implementation which sends off messages to be read when it receives any data on the connection. This lets us scale to a much larger number of connections. - The reader buffer is eliminated, because we directly read from the connection now. https://mattermost.atlassian.net/browse/MM-21012 ```release-notes Improved the websocket implementation by using epoll manually to read from a websocket. As a result, the number of goroutines is expected to go down by half. ``` * fix tests * fix shadowing errors * final changes * windows support! * Remove pointer to waitgroup * Fix edge case * Trigger CI * Trigger CI Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
44 строки
925 B
Go
44 строки
925 B
Go
package pool
|
|
|
|
import "github.com/gobwas/pool/internal/pmath"
|
|
|
|
// Option configures pool.
|
|
type Option func(Config)
|
|
|
|
// Config describes generic pool configuration.
|
|
type Config interface {
|
|
AddSize(n int)
|
|
SetSizeMapping(func(int) int)
|
|
}
|
|
|
|
// WithSizeLogRange returns an Option that will add logarithmic range of
|
|
// pooling sizes containing [min, max] values.
|
|
func WithLogSizeRange(min, max int) Option {
|
|
return func(c Config) {
|
|
pmath.LogarithmicRange(min, max, func(n int) {
|
|
c.AddSize(n)
|
|
})
|
|
}
|
|
}
|
|
|
|
// WithSize returns an Option that will add given pooling size to the pool.
|
|
func WithSize(n int) Option {
|
|
return func(c Config) {
|
|
c.AddSize(n)
|
|
}
|
|
}
|
|
|
|
func WithSizeMapping(sz func(int) int) Option {
|
|
return func(c Config) {
|
|
c.SetSizeMapping(sz)
|
|
}
|
|
}
|
|
|
|
func WithLogSizeMapping() Option {
|
|
return WithSizeMapping(pmath.CeilToPowerOfTwo)
|
|
}
|
|
|
|
func WithIdentitySizeMapping() Option {
|
|
return WithSizeMapping(pmath.Identity)
|
|
}
|