uWebSockets.js/README.md

100 lines
3.9 KiB
Markdown
Raw Normal View History

2019-01-15 13:33:43 +00:00
<div align="center">
<img src="misc/logo.svg" height="180" />
2018-11-04 23:00:00 +00:00
2019-02-04 21:23:12 +00:00
*µWebSockets™ (it's "[micro](https://en.wikipedia.org/wiki/Micro-)") is simple, secure & standards compliant web I/O for the most demanding*<sup>[[1]](https://github.com/uNetworking/uWebSockets/tree/master/benchmarks)</sup> *of applications.*
2018-07-28 20:48:22 +00:00
2019-02-10 22:35:51 +00:00
• [TypeScript docs](https://unetworking.github.io/uWebSockets.js/generated/) • [Read more & user manual (C++ project)](https://github.com/uNetworking/uWebSockets/blob/master/misc/READMORE.md)
2019-01-15 13:33:43 +00:00
</div>
2019-02-15 03:54:23 +00:00
### Outrun. Everyone.
2019-02-21 21:33:57 +00:00
This project is not your typical "web framework" à la 500 lines of JavaScript and a fancy logo. No, you're looking at a three part software suite of ~7k lines of C & C++, working in unison with Google V8 to bring you one of the most memory scalable and performant I/O scripting environments available.
2019-01-15 13:33:43 +00:00
2019-02-15 03:54:23 +00:00
It runs 15x faster than Deno and scales to millions of connections using less than half a GB of user space memory.
2019-02-14 04:45:26 +00:00
2019-02-20 17:24:57 +00:00
[Read the release post](https://levelup.gitconnected.com/will-node-js-forever-be-the-sluggish-golang-f632130e5c7a) and/or the [1 million WebSockets post](https://medium.com/@alexhultman/millions-of-active-websockets-with-node-js-7dc575746a01).
2019-02-10 23:06:50 +00:00
### No compiler needed.
We use AppVeyor & TravisCI to automatically pre-compile binaries for Linux, macOS and Windows with every push. New releases are tagged from branch `binaries` and can be installed [using NPM](https://docs.npmjs.com/cli/install) like so:
2018-12-26 08:15:31 +00:00
```
2019-03-01 19:59:30 +00:00
npm install uNetworking/uWebSockets.js#v15.4.0
2018-12-26 08:15:31 +00:00
```
2019-03-01 19:59:30 +00:00
where `v15.4.0` is the particular Git tag you wanted to use. "Nightly" builds can be installed with suffix `#binaries`.
2018-11-04 23:00:00 +00:00
2019-02-10 23:13:51 +00:00
### In a nutshell
There are tons of [examples](examples) but here's the gist of it all:
2019-01-15 13:33:43 +00:00
```javascript
2019-02-10 23:13:51 +00:00
const uWS = require('../dist/uws.js');
const port = 9001;
const app = uWS.SSLApp({
key_file_name: 'misc/key.pem',
cert_file_name: 'misc/cert.pem',
passphrase: '1234'
}).ws('/*', {
/* Options */
compression: 0,
maxPayloadLength: 16 * 1024 * 1024,
idleTimeout: 10,
/* Handlers */
open: (ws, req) => {
console.log('A WebSocket connected via URL: ' + req.getUrl() + '!');
},
message: (ws, message, isBinary) => {
/* Ok is false if backpressure was built up, wait for drain */
let ok = ws.send(message, isBinary);
},
drain: (ws) => {
console.log('WebSocket backpressure: ' + ws.getBufferedAmount());
},
close: (ws, code, message) => {
console.log('WebSocket closed');
}
}).any('/*', (res, req) => {
res.end('Nothing to see here!');
2018-11-04 23:00:00 +00:00
}).listen(port, (token) => {
if (token) {
console.log('Listening to port ' + port);
} else {
console.log('Failed to listen to port ' + port);
}
2018-10-04 21:18:50 +00:00
});
2018-07-28 20:48:22 +00:00
```
2018-11-03 11:45:56 +00:00
2019-01-15 13:33:43 +00:00
### Streams
Proper streaming of huge data is supported over Http/Https and demonstrated with examples. Here's a shot of me watching real-time streamed HD video from Node.js while simultaneously scoring a 115k req/sec with wrk. For my computer, that's about 5x that of vanilla Node.js (without any HD video streaming/playing).
![](misc/streaming.png)
2019-02-10 23:13:51 +00:00
### Pub/sub
WIP section --
2018-11-03 11:45:56 +00:00
### Benchmarks
2019-02-14 04:45:26 +00:00
In the following charts "µWS v0.15" denote the C++ project - performance retention for µWebSockets.js inside of V8 is about 65-75%, similar to or above the top performing Golang modules. User space memory usage for a million WebSockets is in the 100-400mb range.
2019-01-15 13:33:43 +00:00
2019-02-13 02:28:31 +00:00
Http | WebSockets | PubSub
--- | --- | ---
![](https://github.com/uNetworking/uWebSockets/blob/master/misc/bigshot_lineup.png) | ![](https://github.com/uNetworking/uWebSockets/blob/master/misc/websocket_lineup.png) | todo: Socket.IO, SocketCluster, ClusterWS
2018-11-03 23:17:07 +00:00
2018-12-26 08:15:31 +00:00
### Build from source
#### Recursively clone, and enter, this repo:
2018-11-03 23:17:07 +00:00
```
2018-11-04 23:00:00 +00:00
git clone --recursive https://github.com/uNetworking/uWebSockets.js.git
cd uWebSockets.js
```
2019-02-15 16:51:59 +00:00
#### For Unix (Linux, macOS, FreeBSD):
```
2018-11-03 23:17:07 +00:00
make
```
#### For Windows (in an x64 developer terminal):
```
nmake Windows
```
#### Test it out
```
2018-11-03 23:17:07 +00:00
node examples/HelloWorld.js
```