T
T
tushev2021-02-14 10:34:27
go
tushev, 2021-02-14 10:34:27

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

5 answer(s)
E
Evgeny Mamonov, 2021-02-14
@tushev

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 :)

A
Alexander Pavlyuk, 2021-02-14
@pav5000

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.

M
mitya_k, 2021-02-14
@mitya_k

  • First, the reason Go is popular for its poor syntax, some people like it...
    For large companies like Google, this is a plus, as you can jail 100,500 programmers who are forced to write a lot of the same type of bolterplate code.
  • The second reason, where it was necessary to solve low-level tasks, without business logic (for example, to work a lot with bytes), plus multithreading was required, for this one had to use C++. Now there is a simple alternative in the form of Go. Again, this is true for large companies where there are similar tasks. For example, write some parser for terabyte logs
  • And lastly, you can generate a binary without dependencies, which DevOps people like, and for scripting a "rich language" is not particularly needed. Again, this is relevant for large companies where there are large DevOps departments.

From all 3 points follows salary and popularity in large companies.

I
index0h, 2021-02-14
@index0h

In what applications is Go significantly more efficient than Node.js and PHP?

Go > PHP:
1. Applications in which a lot of time is spent on initialization and this is critical. Roughly speaking, when a dying execution model doesn't fit.
2. Applications that need a lot of memory for processing.
3. Applications that require multithreading and the implementation of time delays.
PHP > Go:
1. Applications in which development speed is important, and performance is in the background.
2. Applications where ease of horizontal scaling is important. Roughly speaking, where the dying model is optimal.

U
Uno, 2021-02-15
@Noizefan

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 question

Ask a Question

731 491 924 answers to any question