Sdk: Optimize Dart for Server use cases

Created on 25 Nov 2019  路  21Comments  路  Source: dart-lang/sdk

Is there any plan to optimize Dart for Server applications?

Dart/Flutter developers would love to use Dart as a Full stack language and I am sure javascript/Nodejs would like to switch If Dart core team decide to make Dart suitable for Server applications.

I would strongly suggest and request Dart team to consider this proposal.

Most helpful comment

@ansarizafar I think the same thing as I have said before - Dart is fast enough to be used on the server. These benchmarks confirm it.

Note: being fast enough and being the fastest are two different things. I don't currently see any reason why Dart should be trying to compete in being the fastest.

Given that it is fast enough I don't think we will be doing any sort of investigation into these particular benchmarks to figure out if they can be made _even faster_. It's a pragmatic prioritisation choice - the whole team is busy focusing on important things which are not good enough.

If somebody in the community does performance analysis and sends us patches to improve VM or dart:io implementation - we will be happy to take those patches.

That said, I would like to reiterate another thing I have mentioned before: if you write some real world application and you hit a performance issue that makes things not work (e.g. something takes seconds instead of milliseconds) please do report this and we will fix it.

All 21 comments

You request are rather vague. Can you be more specific of what features your are missing? There are already multiple mature server frameworks on pub.dev.

We are aware of multiple teams across multiple companies using Dart on the server side (both natively on the Dart VM and on node.js via dart to javascript compilation) - so for all intents and purposes you can already use Dart on the Server side.

There are multiple server side frameworks available for Dart.

And pub.dev in fact is an example of Dart team running Dart on the server side ourselves.

We are also happy to address performance issues - if you discover some.

It is mentioned on dart.dev

Dart is a client-optimized language for fast apps on any platform

The core developer of Angel framework @thosakwe said yesterday. https://gitter.im/angel_dart/discussion

I would expect Dart memory usage to be higher than Node.js and Asp.NET, and I would also expect requests/sec to be less, because Dart's not really optimized for the server.
If you're running on a VPS, or for a long time, use JIT because performance can steadily improve. If you're going serverless, just go AOT because of faster startup, and because performance can be pretty static and tolerated. I also wish it were optimized by server, but I can understand why it's not a goal. Dart server-side usage is small, so it's a bit of a chicken-and-egg problem.

What is your recommendation for using a dart server app in production dart vm or complied binary with dart2native?

Can we compare the performance of a Dart server complied with dart2native in terms of CPU/Memory usage and request per second with Nodejs/, Asp.net core and Go lang?

Dart is an amazing language, much much better than javascript and developer experience is amazing. I would love and hope to see this soon on dart.dev

Dart is a server and client optimized language for fast and efficient back-end and front-end apps on any platform

I guess the recommendation for JIT vs AOT is what your own comment says? If you have a VPS running your server software then the JIT version are properly the best if you can live with the higher memory usage. If you don't have much memory or uses some kind of web services which needs to spin up fast then the AOT version are the best.

About the performance differences then it will be entirely up to each use case since the difference between AOT and JIT is affected by what you server are doing. E.g. RegEx are still an expensive operation in AOT so if your application are using a lot of RegEx operations then your will see a bigger difference between AOT and JIT.

Therefore, if you need performance data for your own use case it is always best to make your own tests since the Dart project cannot possible make enough test cases to be relevant for all the different use cases.

If you find any specific performance issues then create an issue for them.

In my opinion JIT should only be available/used for development only. Why can't we make Dart AOT efficient for all use cases in terms of performance, memory/cpu usage, binary size, request per second and make it comparable to Go lang or other efficient languages? This is the purpose, desire. hope and request for raising this issue.

See the following for some good reasons why JIT will properly always be faster for long running applications (like servers):
https://github.com/dart-lang/sdk/issues/39367#issuecomment-554331110
https://github.com/dart-lang/sdk/issues/39367#issuecomment-555192546

@ansarizafar I would not read to much into "client-optimized language" statement or @thosakwe's statement that Dart is not "optimized for the server". Dart VM can run in a variety of environments and modes and we tend to think that it does pretty good job in all of them. It is true that during different periods we might be focusing our attention more on certain environments and modes - but it does not mean that this regresses other variants.

FWIW I would expect Dart VM for a real server application to have a smaller memory footprint than node.js - when it is used in the right way (that for example means using app-jit or app-aot snapshot), just because Dart has an object model that is more static compared to the JavaScript one.

Sorry if I caused any confusion. The Dart VM is definitely already good enough on the server, which is why people use it.

And the last point is interesting; I had actually only done deployments without snapshots, and this carried over into past benchmarks I had done.

@mraleph @thosakwe thanks for the clarification.

Server less (AWS Lamda) is a new trend and the future of back-end development/deployment. Dart AOT is more relevant as in server less environment startup performance, run-time performance and CPU/Memory efficiency are very important.

Dart developers would love use this amazing language to build Rest Apis, Graphql and GPRC servers, compile with dart2native and deploy to AWS lamda . Our goal with AOT should be to achieve performance comparable to Go lang and other similar languages and when this will happen, Dart will become first choice for Full stack development. I am sure Dart core team and opensource contributors like @thosakwe has the ability to achieve this goal. After this discussion, I am very hopeful and switching to dart for back-end/front-end development I am sue I will never regret my decision.

I have found this benchmark showing Dart http server performance, CPU and Memory usage https://github.com/costajob/app-servers

@mraleph https://docs.google.com/spreadsheets/d/1XxacDR05qPyVnb66yRfrEr_b0P84e56xqv_AHSnj41o/edit?usp=sharing I made measurements from which we can conclude that processing is at least 2-3 times worse than nodejs.

If Dart VM is 2-3 times slower then a binary compiled with Dart2native would be much slower than that. I think throughput is worse as Dart is consuming to much CPU.

@DisDis It's 26K res/s vs 86K req/s sending 'Hello, World!'. I mean surely if you want to setup a server replying 'Hello, World!' and you expect it to be hammered by requests then you maybe should consider node.js. You know what would be even faster? Something like nginx serving a static page with Hello World in it. That's why I think that while this measurements are educational (yeah, maybe there are some bottlenecks to fix somewhere in the Dart VM or in the dart:io implementation), they are not really useful.

In the real world performance most likely will be good enough (and bottlenecks would be somewhere else - e.g. talking to your microservices, database, etc).

@mraleph I just wanted to highlight that there is some kind of bottleneck in 'dart: io'. And it practically does not depend on the program code.
1
2

And in a real application there are many other places that will slow down)

These benchmarks are at least showing that Dart is consuming too much CPU for even a simply task like replying 'Hello, World!' surely there are some bottlenecks in 'dart: io'. Memory usage is fine If you compare it with Nodejs but much higher than other efficient languages. Developers wish to see amazing dart on par with Go, Crystal, Nim etc so that they can switch to Dart for full stack development. I would recommend reopening this issue for the community to share ideas, suggestions and report their findings to further optimize Dart for server use cases.

https://www.techempower.com/benchmarks/#section=data-r18&hw=ph&test=json&l=zih7nj-f
A few more different tests (NodeJs vs DartVM).

@mraleph What do you think about above mentioned benchmarks?

@ansarizafar I think the same thing as I have said before - Dart is fast enough to be used on the server. These benchmarks confirm it.

Note: being fast enough and being the fastest are two different things. I don't currently see any reason why Dart should be trying to compete in being the fastest.

Given that it is fast enough I don't think we will be doing any sort of investigation into these particular benchmarks to figure out if they can be made _even faster_. It's a pragmatic prioritisation choice - the whole team is busy focusing on important things which are not good enough.

If somebody in the community does performance analysis and sends us patches to improve VM or dart:io implementation - we will be happy to take those patches.

That said, I would like to reiterate another thing I have mentioned before: if you write some real world application and you hit a performance issue that makes things not work (e.g. something takes seconds instead of milliseconds) please do report this and we will fix it.

I am starting a new Flutter project and wanted to use Dart on the server but the client refused to accept Dart for server development as he said Dart is inferior to Go and even Nodejs in-terms of performance and memory, cpu usage and availability of packages for server for different tasks.

I understand that Dart team has finite resources but I am highly disappointed to know that optimizing amazing Dart for server use cases is not a priority. Unfortunately, switching back to Go for the next project on the client request.

I agree that dart is fast enough, all the need is database API.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DartBot picture DartBot  路  3Comments

gspencergoog picture gspencergoog  路  3Comments

ranquild picture ranquild  路  3Comments

matanlurey picture matanlurey  路  3Comments

rinick picture rinick  路  3Comments