npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

uuws

v0.7.1

Published

Highly scalable WebSocket server library

Downloads

326

Readme

  • Autobahn tests all pass.
  • Linux, OS X & Windows support.
  • Valgrind clean.
  • Built-in load balancing and multi-core scalability.
  • SSL/TLS support & integrates with foreign HTTPS servers.
  • Permessage-deflate built-in.
  • Node.js binding exposed as the well-known ws interface.
  • 10-30x faster than ws (if they are "fastest", we are "fastester").
  • Optional engine in projects like Socket.IO, Primus & SocketCluster.

npm version

Benchmarks table - validate

Implementation | User space memory scaling | Connection performance | Short message throughput | Huge message throughput --- | --- | --- | --- | --- libwebsockets 2.0 | µWS is 11x as lightweight | µWS is equal in performance | µWS is 6x as performant | µWS is 4x in performance ws v1.1.0 + binary addons | µWS is 47x as lightweight | µWS is 18x as performant | µWS is 33x as performant | µWS is 2x as performant WebSocket++ v0.7.0 | µWS is 63x as lightweight | µWS is 4x as performant | µWS is 3x as performant | µWS is 2x as performant Kaazing Gateway Community 5.0.0 | µWS is 62x as lightweight | µWS is 15x as performant | µWS is 18x as performant | unable to measure

Benchmarks are run with default settings in all libraries, except for ws which is run with the native performance addons. These results were achieved with the native C++ server, not the Node.js addon. Expect worse performance and scalability when using Node.js (don't worry, the Node.js addon will run circles around ws).

What others are saying

With changing one letter in the code from "ws" to "uws" I've been able to serve twice as many players for the same cost. - Rezoner / wilds.io

Usage

Node.js

We built µWS with the existing Node.js infrastructure in mind. That's why we target the widespread ws interface, allowing us to seamlessly integrate with projects like SocketCluster, Socket.IO & Primus.

SocketCluster

Use the new wsEngine: 'uws' option like so:

var socketCluster = new SocketCluster({ wsEngine: 'uws' });

We've worked closely together with the SocketCluster team and aim to bring you µWS as the default WebSocket engine in SocketCluster 5.

Socket.IO

Use the new wsEngine: 'uws' option like so:

var io = require('socket.io')(80, { wsEngine: 'uws' });

This option has not yet been released, one alternative way of enabling uws in current versions of Socket.IO is:

var io = require('socket.io')(80);
io.engine.ws = new (require('uws').Server)({
    noServer: true,
    clientTracking: false,
    perMessageDeflate: false
});
Primus

Set 'uws' as transformer:

var primus = new Primus(server, { transformer: 'uws' });
ws

If your code directly relies on ws you can simply swap require('ws') with require('uws'):

var WebSocketServer = require('uws').Server; /* you replace 'ws' with 'uws' */
var wss = new WebSocketServer({ port: 8080 });

wss.on('connection', function (ws) {
    ws.on('message', function (message) {
        console.log('received: ' + message);
    });

    ws.send('something');
});

C++

For maximum performance and memory scaling the native interface is recommended. Look in the examples folder for threading and load balancing examples. There is no documentation written yet but a bright person like you will have no problem just reading the header file.

int main()
{
    /* this is an echo server that properly passes every supported Autobahn test */
    uWS::Server server(3000);
    server.onConnection([](uWS::WebSocket socket) {
        cout << "[Connection] clients: " << ++connections << endl;
    });

    server.onMessage([](uWS::WebSocket socket, char *message, size_t length, uWS::OpCode opCode) {
        socket.send(message, length, opCode);
    });

    server.onDisconnection([](uWS::WebSocket socket) {
        cout << "[Disconnection] clients: " << --connections << endl;
    });

    server.run();
}

Quality control

  • Valgrind clean.
  • Autobahn tests all pass.
  • All Primus transformer integration tests pass.
  • All Engine.IO server tests pass.
  • Small & efficient code base.

Installation

Node.js

npm install --save uws
  • Node.js 4.x, 5.x & 6.x supported
  • Linux & Mac OS X 10.7+

Node.js is broken on Windows and needs to be fixed for us to support the platform

Manual compilation

If you for some reason want and/or need to build the Node.js addon from source:

  • Jump to nodejs folder:
    • cd uWebSockets/nodejs
  • Compile the project:
    • make

This populates the nodejs/dist folder with binaries.

Native developers

Dependencies

First of all you need to install the required dependencies. On Unix systems this is typically done via package managers, like homebrew in the case of OS X or dnf in the case of Fedora Linux. On Windows you need to search the web for pre-compiled binaries or simply compile the dependencies yourself.

  • libuv 1.x
  • OpenSSL 1.0.x
  • CMake 3.x

Compilation

Obviously you will need to clone this repo to get the sources. We use CMake as build system.

  • git clone https://github.com/alexhultman/uWebSockets.git && cd uWebSockets
  • cmake .

Now, on Unix systems it should work by simply running make. Run [sudo] make install as you wish.

Windows, in all its glory

If you are running Windows you should now have a bunch of Visual Studio project files and one solution file. Open the solution file, now you need to make sure the header include paths and library paths are all set according to where you installed the dependencies. You might also need to change the names of the libraries being linked against, all according to the names of the installed library files. You know the drill.