question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How does this work with spirit? It’s a really important part of any webserver.

Would be nice to have an example in the guide an possibly even an included parser in spirit (like ['ip', 'headers']).

Any help is appreciated, even if it’s just telling me where I can find the information needed to assemble the body myself.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
hnrycommented, Oct 14, 2016

I spoke to @dodekeract in gitter, to recap some main points from there:

I know most of this discussion comes from the article I wrote about spirit performance.

Good fundamentals, not micro optimizing

The article was about how structural changes / implementation as a whole can affect performance. And as along as you come into designing something with good fundamentals, you get good results (ie: never wrote spirit to be fast, it just happened that way).

Remember not every request has a request body.

‘Native’ vs using spirit-express

A ‘native’ body parser would be nice (it is on my list of todos). The performance difference between using spirit-express and it just being native is really small. Any performance benefit comes from rewriting the core functionality from whatever express middleware, and not so much from not having to use spirit-express.

My issue with spirit-express was never the performance, that’s why I quote the word “native”. That word in general makes it sound much faster haha. But my issue was you lose out on the benefits of spirit, (testability, thinking about a request / response as being transformed vs changes being crammed onto a req / res object).

Middleware is slow anyway

Using middleware in express or spirit or anything else will take a hit in performance regardless of what the middleware does. Reason usually varies for that project. For spirit, it’s because of Promises (or enforcing use of Promise). Remember also in spirit middlewares return, they rewind back vs callback based of only ‘going forward’.

Is middleware use slower than express?

No, it’s still faster.

I got a lot of comments for my article about why I didn’t test using middleware / logic. And I didn’t understand the point of it.

If I tested spirit and express and had the test both use the “body-parser” module, what’s the point of it? The body-parser performance is relative to itself and not to spirit or express. So if spirit is faster than express, using body-parser, passport, or whatever else, you would see the same results.

Informal Benchmarks

Informal meaning I just put it together real fast to show my point:

Every request is a POST with a small body.

spirit + body-parser via spirit-express:

Running 7s test @ http://localhost:3001
  8 threads and 50 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     5.56ms    1.49ms  15.26ms   88.96%
    Req/Sec     1.09k    86.73     1.27k    80.18%
  60761 requests in 7.03s, 9.62MB read
Requests/sec:   8642.64
Transfer/sec:      1.37MB

express + body-parser:

Running 7s test @ http://localhost:3001
  8 threads and 50 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    15.43ms    3.86ms  80.71ms   95.77%
    Req/Sec   394.38     56.74   464.00     91.79%
  22036 requests in 7.02s, 4.75MB read
Requests/sec:   3138.56
Transfer/sec:    692.69KB

Results

Both spirit and express take a big hit when you use a middleware (body-parser in this case). Is it because of body-parser ? Yea because it’s not a cheap operation, but also you have to pay a price for just using middleware in general.

This ended up being long haha, maybe I’ll convert it into a follow up article / post. Also I do think the body-parser can and should be re-written. I think the performance difference would be minor (when compared to the grand scheme of things), but still worth the effort as it’s a small project.

0reactions
FlorianWendelborncommented, Mar 23, 2017

Closing in favor of dodekeract/spirit-body.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Understanding Body Parser In Express JS - Simplilearn
Body -parser parses is an HTTP request body that usually helps when you need to know more than just the URL being hit....
Read more >
body-parser - npm
Node.js body parsing middleware. Parse incoming request bodies in a middleware before your handlers, available under the req.body property.
Read more >
Body-parser middleware in Node.js - GeeksforGeeks
Body -parser is the Node.js body parsing middleware. It is responsible for parsing the incoming request bodies in a middleware before you ...
Read more >
What is Express body-parser? - Educative.io
Express body-parser is an npm library used to process data sent through an HTTP request body. It exposes four express middlewares for parsing...
Read more >
How to use body parser in express for handling POST requests
Body parser when used inside Express allows you to easily parse the body for different Content-Types in POST requests coming from tag, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found