mrauhu / meteor-clusterws

Guide for adding support of 🚀 ClusterWS in the Meteor
7 stars 0 forks source link
bindings clusterws cpp ddp meteor meteor-package meteorjs node nodejs websocket websocket-server websockets

☄ Meteor + 🚀 ClusterWS

How to make the Meteor consume less CPU and RAM

Use stream-server-uws

See also: https://github.com/meteor/meteor/pull/10120

Introduction

By default, the Meteor Stream Server using the SockJS library for handling WebSocket messages of the Distributed Data Protocol (DDP).

The advantage of the SockJS library is that if the WebSocket protocol are not supported by a browser, then it allows you to use alternative transports.

The disadvantage it is eating CPU and RAM, and with a large number of DDP connections and messages, the memory starts to leak.

Can I use WebSockets only?

This solution based on the ClusterWS/cWS — C++ WebSocket implementation for Node.js.

How to use it now

Prerequisites

Open your project:

cd your-project-root

If your project not a Git repository then initialize it:

git init

Installing

  1. Replace ddp-server and socket-stream-client, install disable-sockjs, stream-server and stream-server-uws packages via Git:

    git submodule add https://github.com/mrauhu/ddp-server packages/ddp-server
    git submodule add https://github.com/mrauhu/disable-sockjs packages/disable-sockjs
    git submodule add https://github.com/mrauhu/socket-stream-client packages/socket-stream-client
    git submodule add https://github.com/mrauhu/stream-server packages/stream-server
    git submodule add https://github.com/mrauhu/stream-server-uws packages/stream-server-uws
  2. Enable Stream Server with the @clusterws/cws:

    meteor add stream-server-uws

Usage

Run the Meteor:

meteor

Have fun

Thanks

Sergey N