boazsegev / facil.io

Your high performance web application C framework
http://facil.io
MIT License
2.16k stars 141 forks source link

How does this compare to Lwan web framework ? #40

Open GuacheSuede opened 5 years ago

boazsegev commented 5 years ago

@GuacheSuede ,

Thank you for your question.

At the moment, I don't know.

I found the old lwan TechEmpower benchmarking code, but it seems that the framework isn't benchmarked anymore. There's a recent discussion about this, so it might be added soon.

This means that the only way to answer is to benchmark the framework independently, which I didn't do yet.

However, here are a few things to consider:

This is pretty much what I could understand after reading through some of the lwan website and documentation. I haven't tested it yet and didn't read the source code, so I'm not sure.

According to TechEmpower's benchmarks, facil.io currently works best on small systems (docker images, etc') and might not utilize multi-core systems as effectively as other solutions (this might be a process/thread ration issue used in the physical server benchmarks).

Please note that the latest TechEmpower benchmarks use facil.io 0.6.x. The 0.7.0.beta2 should be faster.


EDIT:

I received a comment about facil.io being ranked very low on the TechEmpower plain text benchmarks.

This is true and is caused by two main facts:

  1. facil.io throttles pipelined requests to protect against DoS while the benchmarks use pipelined requests (as discussed here); and

  2. facil.io's TechEmpower application is optimized for the cloud benchmarking environment rather than the physical one.

Also, facil.io ranks very high (94.8% out of a maximum of 100% performance speed) on the JSON serialization benchmark in the cloud environment for round 17.

I would also note that facil.io was one of the highest ranking frameworks on round 17 where overhead was concerned (speed isn't the only measure for performance).

GuacheSuede commented 5 years ago

@boazsegev Thanks for the detailed response, i think libH2O/ H2o Server is very similar to Facil.IO in performance too.

GuacheSuede commented 5 years ago

@boazsegev would you be able to pin point the code segment that throttles ?

boazsegev commented 5 years ago

@GuacheSuede , the throttling code is here.

Basically, once the pipeline_limit is reached (8 requests), facil.io will stop handling further requests and force the connection to the end of the event queue - which means that the IO reactor polling will occur before any further request handling.

P.S. (edit)

Also, the connection itself is excluded from the IO reactor during this cycle.

GuacheSuede commented 5 years ago

@boazsegev Assuming overhead was of no concern within reasonable limits, what would you improve in facilIO to improve speed ?

boazsegev commented 5 years ago

@GuacheSuede , that's a great question.

Performance isn't just speed. Security, memory use, energy consumption and development ease are also consideration (IMHO).

Honestly, I don't know where I would improve.

Testing with Valgrind shows that a lot of time is spent on string data management and hash map rehashing (especially when adding headers to the output and formatting the HTTP output).

This is a direct result of copying data from the HTTP parser and delaying data "writes" to the HTTP output stream...

This was a compromise between speed on one hand and memory consumption and security on the other (as well as some features that resulted from the approach). I debated about this choice for a long time, since I'm saving memory and adding flexibility at the expense of CPU.

On the other hand, I provide example code that avoids data copying (while sacrificing the resulting features and flexibility)... So people who prefer speed can easily use facil.io for speed.

My current performance wishes include:

boazsegev commented 5 years ago

@GuacheSuede ,

P.S.

I would point out that on my list of things to do, at the moment, SSL/TLS, HTTP/2 and PostgreSQL integration have a higher priority than most performance concerns.

GuacheSuede commented 5 years ago

Thanks for the detailed reply @boazsegev. Have you considered using green threads to speed it up ?

HTTP/2 yup, I agree that is more important, may I ask what is the current status ?

boazsegev commented 5 years ago

@GuacheSuede

may I ask what is the current status ?

I'm a single person working on this project on my spare time. Things move along at intervals and I make no promises as to when or if any future features will be released.

In practice, HTTP/2 requires SSL/TLS. So this needs to be done before I start working on the HTTP/2 layer.

At the moment, I finished re-writing and testing the Read/Write hooks and I finished designing an initial SSL/TLS API draft.

These two layers are important, since they will allow SSL/TLS connections to use the same API as non-SSL/TLS connections, making security easier for developers.

Currently I hope to support both OpenSSL and BearSSL using buffered IO (BIO). However, I'm a little busy with other projects and probably won't get to it very soon.

Once I finish with the SSL/TLS layer I'll be able to move on to the HTTP/2 part.

Have you considered using green threads to speed it up?

Green thread implementations might be too architecture specific.

I'm trying to avoid CPU assumptions when possible.

Also, green threads add a number of concerns that facil.io won't be able to handle. For example, what if a database library uses a blocking IO function call? - in such a case, the green thread will block the whole framework while today's multi-threading approach will only block a single working thread.

Instead, facil.io offers an evented API. If the evented API is properly utilized, a single thread should perform the similarly to green threads (with the added benefit that more than a single thread can be utilized).