Performance aspect of Deno vs. Node
Published: 2020-06-18 04:59:35

### Talking about performance is cool

A few days ago, I read Craig Morten's post: [What Is The Best Deno Web Framework?](https://dev.to/craigmorten/what-is-the-best-deno-web-framework-2k69) It gives an overview of all the Deno frameworks and compares all the aspects of them. If you haven't read about it, I highly encourage you to do so.

From Craig's post, the section **"Performance"** is fascinating; In his environment, **Deno HTTP module** gets almost the **same result(even more) as Node HTTP module**, which amazes me, even though it's just a "Hello Deno!" benchmark test.

~~**But**, I knew it's not true for most of the cases. Because deno HTTP module is written in Typescript. Type checking brings pleasure for development, but it costs more resources in compiler time thus has a negative effect on performance.~~
(Thanks for Oghenovo Usiwoma and Jonathan Beaumont point out [in the comment](https://dev.to/eunovo/comment/10hn2))

But I've tested it before and never got the same result as his. So I would like to see what would happen when I run tests in a more powerful machine. 

- Environment:
  - CPU: i5-9600KF @3.7GHz
  - RAM: 16GB DDR4 2133MHz
  - OS: Windows 10
  - Benchmark tool: [autocannon](https://github.com/mcollina/autocannon)

- Benchmark Script:
  - "Hello World!" [deno server](https://github.com/deligenius/deligenius/blob/master/benchmark/deno.http.ts) 
  - "Hello World!" [node server](https://github.com/deligenius/deligenius/blob/master/benchmark/node.http.js)

Let's see the result first:

#### 100 concurrent connections

-------------------------------------
Name        | version | AVG req/sec |
------------|---------|-------------|
node.http   | 12.16.3 | 47969.2     |
deno.http   | 1.0.0   | 47376       |
deno.http   | 1.1.0   | 46953.7     |
node.http   | 14.2.0  | 44409       |

Wow! Looks like deno beat node overall! (at least for the version 14.2.0). 

But wait, this benchmark is based on 100 concurrent connections by `autocannon http://localhost:3000/ -c100`, which is too many for a small-to-medium-sized server. So I  give it another try: this time, I use `-c10`, which keeps sending requests in 10 concurrent connections.


#### 10 concurrent connections

-------------------------------------
Name        | version | AVG req/sec |
------------|---------|-------------|
node.http   | 12.16.3 | 49926.69    |
node.http   | 14.2.0  | 45345.33    |
deno.http   | 1.1.0   | 34806.79    |
deno.http   | 1.0.0   | 34742.37    |


This time, node is absolutely the winner. There is a significant difference between the two, node has more than about 10K requests per second than deno. 
 
But, this brings a new question: 

---

### Why does the concurrent connection number matter?

**A concurrent connection** is a [connection happening with another connection at the same time. ](https://blog.litespeedtech.com/2013/04/26/concurrent-connections-demystified/#:~:text=A%20concurrent%20connection%20is%20a,mean%20the%20exact%20same%20time.)
A user sends a request for an HTML page, then after 5ms 
 another user sends a request for a css file, which is not considered as a concurrent connection.

---

### Calculate concurrent connection

Let's say, you have 100 active users on an app. You track these users for an hour and find out each of them makes 60 clicks an hour. That's 6000 total requests on the server, and each request takes 2 seconds(which is very slow). That's 12000 seconds of active connections in 3600 seconds(an hour), which results **3.33 concurrent connections** (12000/3600 = 3.33). 

If the server is powerful enough to allow processing each request within 1 second? 
- The concurrent number is even fewer, less than 1.7.

How about 1000 active users? 
- We get 33.3 concurrent connections

Are 100 concurrent connections overkill?
- Yes, absolutely! Except you want to build a enterprise-level application that serves 3000+ active users(in above scenario).

---

### Can you please tell me which one performs better? Node or Deno.

With that said, **the result with 10 concurrent connections is more meaningful in reality**, **Node wins for the performance round.**

Though deno performs better in the `-c100` test, which means deno is doing better than node in a higher traffic network. That's great. From what I've seen, companies would prefer Java or other well known and proven languages to handle a huge amount of traffic over deno, since deno is still young and it's not production-ready yet at this point. However, everyone in deno community is making it happening 🔥.

At last, I also want to mention one point. Performance is not the key of success for a dev community. Look at Python and PHP, they [preform much slower](https://dev.to/craigmorten/what-is-the-best-deno-web-framework-2k69) than node and deno. What makes them popular? The ecosystem and peoples! 

---

### Extra topic
Consider of [Google handles over 75,000 queries per second](https://99firms.com/blog/google-search-statistics/). 
Can your server handle this amount of request (>40K) per second?