Restructure project
This commit is contained in:
parent
79eab43abc
commit
50641ab8a4
48
README.md
48
README.md
@ -1,26 +1,40 @@
|
||||
**µWebSockets.js** is a JavaScript platform, runtime and web server built on [µWebSockets](https://github.com/uNetworking/uWebSockets) v0.15 and V8.
|
||||
<div align="center">
|
||||
<img src="misc/logo.svg" height="180" />
|
||||
|
||||
There are two modes; compiled as a stand-alone JavaScript runtime or as a Node.js native addon.
|
||||
*µWebSockets™ (it's "[micro](https://en.wikipedia.org/wiki/Micro-)") is simple, secure & standards compliant web I/O for the most demanding*<sup>[[1]](benchmarks)</sup> *of applications.*
|
||||
|
||||
For the most common Node.js systems are available precompiled binaries:
|
||||
• [Read more](misc/READMORE.md)
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
### NPM install
|
||||
While not physically hosted by NPM, it's still possible to install using NPM tools like so (or any such version):
|
||||
|
||||
```
|
||||
npm install uNetworking/uWebSockets.js#semver:0.0.1
|
||||
```
|
||||
|
||||
or any such version.
|
||||
### Presenting; faster I/O for Node.js
|
||||
Every other week a new "web framework" pops up for Node.js. Fastify, Restana, Aero, Micro and so on. Most aim to improve I/O performance, but fall flat. You can't fix an inherent design flaw of an entire stack just by slapping a few lines of JavaScript on top.
|
||||
|
||||
µWS.js is a 100% C/C++ web platform completely bypassing the entire Node.js I/O stack. JavaScript-exposed functions and objects are entirely backed by native code all the way down to the OS kernel. This makes it possible to reach unprecedented I/O performance from within Node.js (or any stand-alone V8 build). Scroll down for benchmarks.
|
||||
|
||||
##### In a nutshell
|
||||
```javascript
|
||||
/* The stand-alone runtime has uWS namespace already loaded. */
|
||||
var uWS = uWS ? uWS : require('../dist/uws.js');
|
||||
|
||||
const world = 'Strings are slower than ArrayBuffer but who cares for demo purose!';
|
||||
const uWS = require('uWebSockets.js');
|
||||
const port = 3000;
|
||||
|
||||
uWS.App().get('/hello', (res, req) => {
|
||||
res.end(world);
|
||||
uWS.SSLApp({
|
||||
/* cert, key and such specified here, or use uWS.App */
|
||||
}).get('/whatsmyuseragent', (res, req) => {
|
||||
res.writeHeader(
|
||||
'content-type', 'text/html; charset= utf-8'
|
||||
).end(
|
||||
'Your user agent is: ' + req.getHeader('user-agent')
|
||||
);
|
||||
}).get('/*', (res, req) => {
|
||||
res.writeHeader('content-type', 'text/html; charset= utf-8').end(req.getHeader('user-agent') + ' är din user agent, biatch!');
|
||||
res.end('Wildcard route');
|
||||
}).listen(port, (token) => {
|
||||
if (token) {
|
||||
console.log('Listening to port ' + port);
|
||||
@ -30,9 +44,17 @@ uWS.App().get('/hello', (res, req) => {
|
||||
});
|
||||
```
|
||||
|
||||
### 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)
|
||||
|
||||
### Benchmarks
|
||||
Performance retention is up to 75% of native C++ [µWebSockets](https://github.com/uNetworking/uWebSockets) v0.15. That puts it some 20x as fast as Deno and even faster than most C++-only servers, all from within a JavaScript VM.
|
||||
![](https://github.com/uNetworking/uWebSockets/blob/master/misc/bigshot_lineup.png)
|
||||
Performance retention is about 65% that of the native C++ [µWebSockets](https://github.com/uNetworking/uWebSockets) v0.15. That makes it some 20x as fast as Deno and even faster than most C++-only servers, all from within a JavaScript VM.
|
||||
|
||||
Http | WebSockets
|
||||
--- | ---
|
||||
![](https://github.com/uNetworking/uWebSockets/blob/master/misc/bigshot_lineup.png) | ![](https://github.com/uNetworking/uWebSockets/blob/master/misc/websocket_lineup.png)
|
||||
|
||||
### Build from source
|
||||
Easiest is to compile yourself a Node.js native addon. The following works for Linux and macOS systems:
|
||||
|
24
addon.pro
24
addon.pro
@ -1,24 +0,0 @@
|
||||
TEMPLATE = app
|
||||
CONFIG += console c++1z
|
||||
CONFIG -= app_bundle
|
||||
CONFIG -= qt
|
||||
|
||||
SOURCES += \
|
||||
src/addon.cpp \
|
||||
uWebSockets/uSockets/src/eventing/epoll.c \
|
||||
uWebSockets/uSockets/src/context.c \
|
||||
uWebSockets/uSockets/src/socket.c \
|
||||
uWebSockets/uSockets/src/eventing/libuv.c \
|
||||
uWebSockets/uSockets/src/ssl.c \
|
||||
uWebSockets/uSockets/src/loop.c
|
||||
|
||||
INCLUDEPATH += targets/node-v11.1.0/include/node
|
||||
INCLUDEPATH += uWebSockets/src
|
||||
INCLUDEPATH += uWebSockets/uSockets/src
|
||||
|
||||
HEADERS += \
|
||||
src/AppWrapper.h \
|
||||
src/HttpRequestWrapper.h \
|
||||
src/HttpResponseWrapper.h \
|
||||
src/Utilities.h \
|
||||
src/WebSocketWrapper.h
|
BIN
benchmarks.png
BIN
benchmarks.png
Binary file not shown.
Before Width: | Height: | Size: 17 KiB |
24
misc/addon.pro
Normal file
24
misc/addon.pro
Normal file
@ -0,0 +1,24 @@
|
||||
TEMPLATE = app
|
||||
CONFIG += console c++1z
|
||||
CONFIG -= app_bundle
|
||||
CONFIG -= qt
|
||||
|
||||
SOURCES += \
|
||||
../src/addon.cpp \
|
||||
../uWebSockets/uSockets/src/eventing/epoll.c \
|
||||
../uWebSockets/uSockets/src/context.c \
|
||||
../uWebSockets/uSockets/src/socket.c \
|
||||
../uWebSockets/uSockets/src/eventing/libuv.c \
|
||||
../uWebSockets/uSockets/src/ssl.c \
|
||||
../uWebSockets/uSockets/src/loop.c
|
||||
|
||||
INCLUDEPATH += ../targets/node-v11.1.0/include/node
|
||||
INCLUDEPATH += ../uWebSockets/src
|
||||
INCLUDEPATH += ../uWebSockets/uSockets/src
|
||||
|
||||
HEADERS += \
|
||||
../src/AppWrapper.h \
|
||||
../src/HttpRequestWrapper.h \
|
||||
../src/HttpResponseWrapper.h \
|
||||
../src/Utilities.h \
|
||||
../src/WebSocketWrapper.h
|
1
misc/logo.svg
Normal file
1
misc/logo.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 12 KiB |
BIN
misc/streaming.png
Normal file
BIN
misc/streaming.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 606 KiB |
Loading…
Reference in New Issue
Block a user