Update README.md

This commit is contained in:
Alex Hultman 2019-03-13 20:52:46 +01:00 committed by GitHub
parent 22847c3e82
commit 41f6ca3eee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,99 +1,47 @@
<div align="center"> <div align="center">
<img src="misc/logo.svg" height="180" /> <img src="misc/logo.svg" height="180" />
*µ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.* *µWebSockets™ (it's "[micro](https://en.wikipedia.org/wiki/Micro-)") is simple, secure*<sup>[[1]](https://github.com/uNetworking/uWebSockets/tree/master/fuzzing)</sup> *& standards compliant web I/O for the most demanding*<sup>[[2]](https://github.com/uNetworking/uWebSockets/tree/master/benchmarks)</sup> *of applications.*
• [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) • [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)
</div> </div>
### Outrun. Everyone. ### In a nutshell.
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. µWebSockets.js is the Google V8 bindings to [µWebSockets](https://github.com/uNetworking/uWebSockets), one of the most efficient web servers available for C++ programming<sup>[[2]](https://github.com/uNetworking/uWebSockets/tree/master/benchmarks)</sup>. Bypassing the entire I/O stack of Node.js allows for unprecedented efficiency in back-end JavaScript - what you build stands on nothing but the best of C and C++. Scales to millions of active WebSockets using half a GB of user space memory<sup>[[3]](https://medium.com/@alexhultman/millions-of-active-websockets-with-node-js-7dc575746a01)</sup>.
It runs 15x faster than Deno and scales to millions of connections using less than half a GB of user space memory.
[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).
### 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:
``` ```
npm install uNetworking/uWebSockets.js#v15.4.0 npm install uNetworking/uWebSockets.js#v15.8.0
``` ```
where `v15.4.0` is the particular Git tag you wanted to use. "Nightly" builds can be installed with suffix `#binaries`. , or any such tag (see [releases](releases)). There are tons of [examples](examples) but here's the gist of it all:
### In a nutshell
There are tons of [examples](examples) but here's the gist of it all:
```javascript ```javascript
const uWS = require('../dist/uws.js'); const uWS = require('uWebSockets.js');
const port = 9001;
const app = uWS.SSLApp({ /* Non-SSL is simply uWS.App() */
uWS.SSLApp({
/* There are tons of SSL options */
key_file_name: 'misc/key.pem', key_file_name: 'misc/key.pem',
cert_file_name: 'misc/cert.pem', cert_file_name: 'misc/cert.pem',
passphrase: '1234'
}).ws('/*', { }).ws('/*', {
/* Options */ /* For brevity we skip the other events */
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) => { message: (ws, message, isBinary) => {
/* Ok is false if backpressure was built up, wait for drain */
let ok = ws.send(message, isBinary); 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) => { }).any('/*', (res, req) => {
/* Let's deny all Http */
res.end('Nothing to see here!'); res.end('Nothing to see here!');
}).listen(port, (token) => { }).listen(9001, (listenSocket) => {
if (token) { if (listenSocket) {
console.log('Listening to port ' + port); console.log('Listening to port 9001');
} else {
console.log('Failed to listen to port ' + port);
} }
}); });
``` ```
### Streams ### Pay what you want.
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). Commercially developed on a sponsored/consulting basis; BitMEX, Bitfinex and Coinbase are current or previous sponsors. Contact [me, the author](https://github.com/alexhultman) for support, feature development or consulting/contracting.
![](misc/streaming.png) ![](https://raw.githubusercontent.com/uNetworking/uWebSockets/master/misc/2018.png)
### Pub/sub *µWebSockets.js is intellectual property licensed Apache 2.0 with limitations on trademark use. Forks must be clearly labelled as such and must not be confused with the original.*
WIP section --
### Benchmarks
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.
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
### Build from source
#### Recursively clone, and enter, this repo:
```
git clone --recursive https://github.com/uNetworking/uWebSockets.js.git
cd uWebSockets.js
```
#### For Unix (Linux, macOS, FreeBSD):
```
make
```
#### For Windows (in an x64 developer terminal):
```
nmake Windows
```
#### Test it out
```
node examples/HelloWorld.js
```