ultimate-express 1.2.14 → 1.2.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -12
- package/package.json +1 -1
- package/src/index.js +6 -0
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ To make sure µExpress matches behavior of Express in all cases, we run all test
|
|
|
17
17
|
Similar projects based on uWebSockets:
|
|
18
18
|
|
|
19
19
|
- `express` on Bun - since Bun uses uWS for its HTTP module, Express is about 2-3 times faster than on Node.js, but still slower than µExpress because it doesn't do uWS-specific optimizations.
|
|
20
|
-
- `hyper-express` - while having a similar API to Express, it's very far from being a drop-in replacement, and implements most of the functionality differently. This creates a lot of random quirks and issues, making the switch quite difficult. Built in middlewares are also very different.
|
|
20
|
+
- `hyper-express` - while having a similar API to Express, it's very far from being a drop-in replacement, and implements most of the functionality differently. This creates a lot of random quirks and issues, making the switch quite difficult. Built in middlewares are also very different, middlewares for Express are mostly not supported.
|
|
21
21
|
- `uwebsockets-express` - this library is closer to being a drop-in replacement, but misses a lot of APIs, depends on Express by calling it's methods under the hood and doesn't try to optimize routing by using native uWS router.
|
|
22
22
|
|
|
23
23
|
## Performance
|
|
@@ -41,16 +41,16 @@ Tested using [wrk](https://github.com/wg/wrk) (`-d 60 -t 1 -c 200`). Etag was di
|
|
|
41
41
|
Tested using [bun-http-framework-benchmark](https://github.com/dimdenGD/bun-http-framework-benchmark). This table only includes Node.js results.
|
|
42
42
|
For full table with other runtimes, check [here](https://github.com/dimdenGD/bun-http-framework-benchmark?tab=readme-ov-file#results).
|
|
43
43
|
|
|
44
|
-
| Framework | Average
|
|
45
|
-
| -------------------- |
|
|
46
|
-
| uws | 94,296.49
|
|
47
|
-
| hyper-express | 66,356.707
|
|
48
|
-
| **ultimate-express** | **
|
|
49
|
-
| h3 | 35,423.263
|
|
50
|
-
| fastify | 33,094.62
|
|
51
|
-
| hono | 26,576.02
|
|
52
|
-
| koa | 24,045.08
|
|
53
|
-
| express | 10,411.313
|
|
44
|
+
| Framework | Average | Ping | Query | Body |
|
|
45
|
+
| -------------------- | -------------- | ------------- | ------------- | ------------- |
|
|
46
|
+
| uws | 94,296.49 | 108,551.92 | 104,756.22 | 69,581.33 |
|
|
47
|
+
| hyper-express | 66,356.707 | 80,002.53 | 69,953.76 | 49,113.83 |
|
|
48
|
+
| **ultimate-express** | **57,343.813** | **64,608.03** | **60,234.78** | **47,188.63** |
|
|
49
|
+
| h3 | 35,423.263 | 41,243.68 | 34,429.26 | 30,596.85 |
|
|
50
|
+
| fastify | 33,094.62 | 40,147.67 | 40,076.35 | 19,059.84 |
|
|
51
|
+
| hono | 26,576.02 | 36,215.35 | 34,656.12 | 8,856.59 |
|
|
52
|
+
| koa | 24,045.08 | 28,202.12 | 24,590.84 | 19,342.28 |
|
|
53
|
+
| express | 10,411.313 | 11,245.57 | 10,598.74 | 9,389.63 |
|
|
54
54
|
|
|
55
55
|
### Performance on real-world application
|
|
56
56
|
|
|
@@ -109,10 +109,12 @@ Optimized routes can be up to 10 times faster than normal routes, as they're usi
|
|
|
109
109
|
|
|
110
110
|
3. Do not use `body-parser` module. Instead use built-in `express.text()`, `express.json()` etc.
|
|
111
111
|
|
|
112
|
-
4. Do not set `body methods` to read body of requests with GET method or other methods that don't need a body. Reading body makes
|
|
112
|
+
4. Do not set `body methods` to read body of requests with GET method or other methods that don't need a body. Reading body makes endpoint about 15% slower.
|
|
113
113
|
|
|
114
114
|
5. By default, µExpress creates 1 (or 0 if your CPU has only 1 core) child thread to improve performance of reading files. You can change this number by setting `threads` to a different number in `express()`, or set to 0 to disable thread pool (`express({ threads: 0 })`). Threads are shared between all express() instances, with largest `threads` number being used. Using more threads will not necessarily improve performance. Sometimes not using threads at all is faster, please [test](https://github.com/wg/wrk/) both options.
|
|
115
115
|
|
|
116
|
+
6. Don't read `req.connection.remoteAddress` (or `req.ip` if `trust proxy` is disabled) after response is finished. In general, reading IP in uWS is quite slow (~15% slower), and you should only read it when you need it while request is still open. If you'll read it after response, it'll make µExpress read IP for every single request after, even when it's not needed.
|
|
117
|
+
|
|
116
118
|
## WebSockets
|
|
117
119
|
|
|
118
120
|
Since you don't create http server manually, you can't properly use http.on("upgrade") to handle WebSockets. To solve this, there's currently 2 options:
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -14,12 +14,18 @@ See the License for the specific language governing permissions and
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
+
const uWS = require("uWebSockets.js");
|
|
17
18
|
const Application = require("./application.js");
|
|
18
19
|
const Router = require("./router.js");
|
|
19
20
|
const middlewares = require("./middlewares.js");
|
|
20
21
|
const Request = require("./request.js");
|
|
21
22
|
const Response = require("./response.js");
|
|
22
23
|
|
|
24
|
+
try {
|
|
25
|
+
// disable Uwebsockets header
|
|
26
|
+
uWS._cfg('999999990007');
|
|
27
|
+
} catch (error) {}
|
|
28
|
+
|
|
23
29
|
Application.Router = function(options) {
|
|
24
30
|
return new Router(options);
|
|
25
31
|
}
|