Answer the question
In order to leave comments, you need to log in
In what applications is Go significantly more efficient than Node.js and PHP?
I became interested in learning the Golang language. My first impression was that Go should show much better performance than Node.js and PHP, for the following reasons: The language is compiled, strongly typed, very similar to C, and therefore should have little overhead like its counterparts Node.js and PHP, built-in lightweight multitasking. Articles constantly write that Go is ideal for writing all sorts of high-performance web services. However, digging a little deeper, I found many articles with benchmarks in which Go does not show any super superiority in performance compared to the same Node.js.
About PHP, it’s clear that classic PHP works according to the request-restart_script-response-dead scheme and this is not super efficient, but there are all sorts of asynchronous PHP solutions that work with almost like Node.js with an event-loop.
On the other hand, Go is more difficult when writing small services than the same Node.js and PHP, at least due to its strong typing and OOP-specific, which is unusual for most developers.
But if Go does not provide some huge advantage, then why is there such a large demand for Go developers and some of the highest salaries in this language now? Why are large companies trying to convert their solutions from PHP to Go? It seems to be much easier to use PHP and Node developers, which are abundant on the market, than to look for rare and expensive Go developers.
Answer the question
In order to leave comments, you need to log in
Benchmarks are good, but it is very important to understand what exactly was measured there and why the results are the way they are.
A few years ago, I also did Python, PHP, Node, Go benchmarks.
Two things were important for me:
1 - server response speed / number of requests per second
2 - service volume in memory, because the cost of resources depends on this
On the test, where the services did not make requests to the database - of all four, Go worked best with a decent margin, unfortunately I don’t remember the numbers.
But all this difference disappeared as soon as only one simple SQL query was added to the database, to a table with 10 rows. Against this background, the difference in response speed was less than 10%.
In other words, if your service works with a database, there will not be a critical difference in speed between Go/Rust/PHP/Node/Java.
Another thing is if your service does not make requests to the database, or caches the results of requests, then you will feel a tangible difference.
It is also very important to understand how much your script consumes resources. This becomes critical when you are dealing with large workloads.
One instance of Go occupied about 6MB of RAM in memory, while Pytho + Django was about 60MB.
Node, I don't remember how many, but something close to Python.
Here already, when you have a lot of servers - the number of servers with Go you will have 10 times less, respectively, the costs for these servers will be 10 times less :)
In large companies where Go specialists are needed, there are already high loads and the transition to Go, and the search for a specialist is due to the need to solve the problem with loads in the first place, to optimize equipment costs.
Somewhere I read an article that people had an API for about 40 servers on Node, after rewriting on Go - there were two servers left, of which the second was a spare :)
There will be no super superiority in performance. But with the right architecture, there will be normal superiority.
In nodejs, for example, to parallelize a task across multiple cores, you need to do a lot of extra work. movements, manually spreading tasks. In Go, this is done automatically and much more conveniently, you just use goroutines, and the runtime itself worries about whether to run them concurrently or in parallel. Well, plus, in go you just write sequential code, instead of callbacks, it's easier.
Strict static typing makes it possible to catch many problems before release, the code simply will not compile, instead of falling in production. This is very critical for large projects with many people working on them. Refactoring is also easier for this reason. PHP and node do not provide such an opportunity.
Go developers are not rare and not expensive, they are quickly brought up from developers in other languages, which is also convenient for companies. Plus, the code is pretty standard, there are almost no multiple ways to do the same thing in Go, it instills a unified approach.
The sum of all these factors is the reason for the popularity of Go.
In what applications is Go significantly more efficient than Node.js and PHP?
There is also a moment of trend following.
At one time, as we all know, the largest web projects worked on PHP, and in the problem of optimizing the whales decided to reinvent the wheel, something in the spirit of their dialects, like fb or vk, someone rewrote the cores into more productive languages, c++ etc etc.
Go, for me personally, seems to be something like a golden mean in the situation I have described.
It is compiled once, twice more efficiently (>php,js), three times more reliable (>php,js), four times easier (>c++). So it satisfies the request above.
And besides, in no case would I develop (read - I wouldn’t rewrite) a project on it until a whole data center has been allocated for the project, and not a shelf on the rack, until the whole world is talking about me.
On the other hand, he has not yet gained that strength in the form of support, community and age (as a criterion of reliability), so that I would prefer him to crosses.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question