Dart vs Node.js: compare performance on HTTP server implementations
Good day to all!
This year, with the release of Flutter - a framework for cross-platform application development, there has been a rise in the Hip language Dart. Like any perfectionistprocrastinator from boredom bummerI thought about comparing the performance of the server implementation of the Dart virtual machine with its potential antagonist, Node.js. I will say right away that there was a hope in me that Dart would win, and I would find the holy grail giving me superiority over potential competitors for the next three five-year plans, but the reality turned out to be a bit different ...
Tools
- Test Machine: Core I7, SSD, 12GB of RAM (kindly provided by my past employer)
- Load testing: k6.io (by the way, the framework is very interesting in its architecture)
Organization code applications
Then I particularly decided not to bother and decided to follow the recommendations that I had read in my time at Habré. In particular:
- Added payload in quality of random data generation (random data to eliminate potential caching of results)
class Human {
constructor (id, name, surname, age, gender) {
this.id = id
this.name = name
this.surname = surname
this.age = age
this.gender = gender
}
}
- As in Dart, Node.js used variants of synchronous and asynchronous processing of the request.
- Applied options for native solutions and options for solutions on industry frameworks (aqueduct for dart and express for node.js)
- Since the study succeeded in obtaining a significant acceleration of Dart operation using aqueduct, which runs isolates on each core, for the purpose of balancing applied the cluster module for node.js
Testing method
- ran load tests with a given number of requests per second (500, 750) and a limit on the number of test iterations (number of completed requests)
- both the application and the testing framework were running on the same machine, respectively, it should be understood that all the results are relative and can only be compared with each other
results
Native dart
500 rps
750 rps
- http_reqs: 309.10154 / s
Aqueduct framework for dart
500 rps
750 rps
Native node.js
500 rps
750 rps
Node Express with Cluster
500 rps
750 rps
findings
- Of course, much depends on how you implemented the application logic, I'm not particularly sure that my code is optimal in the case of both dart and node.js
- In particular, the array generation function could be output to a separate worker thread with asynchronous output, in my case it was not implemented, therefore the whole asynchronous path is not really used here
- In both Dart and Node.js, output could be organized through the stream
- Therefore, there is still a lot of space for performance research and optimization.
- Dart in the native implementation of the handlers showed an epic file, however, when implemented through the framework showed impressive results, according to which the Dart virtual machine can already compete with Node.js
- As far as I know, an enormous amount of man-hours of work has been invested in optimizing V8 work, I am more than confident that much less time is invested in the Dart virtual machine. Therefore, the second one probably has a rather large potential for optimizations before the V8