diff --git a/app/web_conn.go b/app/web_conn.go index 9618365de7..c562426375 100644 --- a/app/web_conn.go +++ b/app/web_conn.go @@ -7,6 +7,7 @@ import ( "bytes" "encoding/json" "fmt" + "net" "net/http" "sync" "sync/atomic" @@ -61,6 +62,17 @@ func (a *App) NewWebConn(ws *websocket.Conn, session model.Session, t i18n.Trans }) } + if a.srv.Config().FeatureFlags.WebSocketDelay { + // Disable TCP_NO_DELAY for higher throughput + tcpConn, ok := ws.UnderlyingConn().(*net.TCPConn) + if ok { + err := tcpConn.SetNoDelay(false) + if err != nil { + mlog.Warn("Error in setting NoDelay socket opts", mlog.Err(err)) + } + } + } + wc := &WebConn{ App: a, send: make(chan model.WebSocketMessage, sendQueueSize), diff --git a/model/feature_flags.go b/model/feature_flags.go index bad40fe2c5..81f1e18c9d 100644 --- a/model/feature_flags.go +++ b/model/feature_flags.go @@ -23,6 +23,8 @@ type FeatureFlags struct { PluginIncidentManagement string `plugin_id:"com.mattermost.plugin-incident-management"` // Toggle on and off support for Files search FilesSearch bool + // Feature flag to control setting the TCP_NO_DELAY setting for websockets. + WebSocketDelay bool } func (f *FeatureFlags) SetDefaults() { @@ -32,6 +34,7 @@ func (f *FeatureFlags) SetDefaults() { f.CollapsedThreads = false f.FilesSearch = false f.PluginIncidentManagement = "1.6.0" + f.WebSocketDelay = false } func (f *FeatureFlags) Plugins() map[string]string {