laitimes

Amazon posted a strong praise for Rust, Go technology head: don't "pull" us!

Author | Chu Xingjuan

Recently, Amazon's official blog posted "Sustainability with Rust", which shows that Rust is superior to other languages in terms of sustainability through research and comparison. Subsequently, ZDNet also reported on this article. After the ZDNet report, Russ Cox, the head of Go technology, sent 14 tweets in a row, saying that the article was seriously misleading everyone's understanding of the Go language.

This matter has attracted everyone's attention, and it has also triggered a big discussion of "Rust or Go". So, what exactly happened?

An article triggers a "line to line"

At Amazon, Rust has become the key to building infrastructure at scale. In 2019, Amazon became a sponsor of the Rust project. In 2020, rust maintainers and contributors were recruited, and the Rust Foundation was formed in partnership with Google, Huawei, Microsoft, and Mozilla.

Controversy 1: Research from a few years ago was biased

In the "Sustainability with Rust" article, data from a 2017 study was used to verify that Rust is an energy-efficient programming language. The study focused on 10 benchmark questions for 27 programming languages and measured execution time, energy consumption, and peak memory usage. The following is the first controversial section of the article:

A few years ago there was a very interesting study that explored the relationship between energy consumption, performance, and memory usage. This is a common topic about sustainability. We know very little about the energy or carbon use of the service, is there a proxy indicator? Can I view a dashboard of services such as existing infrastructure costs, performance, memory, etc., and infer the energy consumption trends of a service based on observed trends?

The study conducted 10 benchmarks in 27 different programming languages and measured execution time, energy consumption, and peak memory usage. C and Rust are significantly better than other languages in terms of energy efficiency. In fact, they are about 50% more efficient than Java and 98% more efficient than Python.

Amazon posted a strong praise for Rust, Go technology head: don't "pull" us!

It's no surprise that C and Rust are more efficient than other languages, but surprisingly the magnitude of the difference. It is conservatively estimated that widespread adoption of C and Rust can reduce compute energy consumption by 50%.

So why don't people use C more? Its language and development tools are very mature, and its community is much larger than Rust's. At the 2021 Open Source Summit, Linux creator Linus Torvalds admitted that implementing code in C is like playing a chainsaw. As a programmer who wrote C for life, Torvalds knew, "[C's subtle type interactions] aren't always logical and are a trap for almost everyone." ”

Torvalds says Rust is the first potentially problem-solving language he's ever seen. Rust provides the same energy efficiency as C, without the risk of undefined behavior. We can halve energy consumption without losing the benefits of storage security.

Multiple analyses show that more than 70% of high-severity CVEs that occur in C/C++ can be prevented by implementing the same solution in Rust. In fact, the Internet Security Research Group (ISRG), a nonprofit that supports the Let's Encrypt project, aims to migrate all of its Internet security-sensitive infrastructure to memory-safe languages, including support for Rust in the Linux kernel and Rust implementations for curl migration to TLS and HTTP.

Let's look at the other findings. The middle column in the figure above shows the test results for execution times, which are very similar in rust and C, both languages perform faster than others. This means that choosing Rust gives you the benefits of sustainability and security while also having the optimized performance of C.

So, what's wrong with this passage in the article? Cox notes that "interesting research from a few years ago" is a glaring problem. The study was conducted in October 2017 using Go 1.6 (February 2016) on Intel i5-4460 CPUs (Q2 2014). "That's forever in the past." On top of that, this "really interesting study" assumes that computer language benchmark games are a comparable source of programs, but if you know this site, you know that this is completely incorrect.

Most notably, Cox says, if the study claims that C++ uses 34 percent more energy, executes 56 percent faster, and has 14 percent more memory than C, it would be necessary to re-examine the study's premises. "Almost every C program is a valid C++ program, so C++ doesn't lose, especially not so badly!"

"So, this 'really interesting study' isn't really interesting. In fact, we should look at it with dialectical skepticism. Cox wrote.

Controversy 2: Unfair contrast

Amazon engineers also use the chat software Discord as an example in the article to talk about the process of switching from Go to Rust. Cox believes that the Discord content it cites is incredibly misleading about switching from Go to Rust. The following is the second part of the article that caused controversy:

Discord was originally dominated by Python, Go, and Elixir, but there was a problem with one of their key Go services. This is a very simple service, but it still causes severe tail latency. This is because Go is a garbage collection (GC) language, so when creating and disposing of objects, the garbage collector has to stop the execution of the program and run a garbage collection every once in a while. When the GC is running, the process cannot respond to requests, and you can see CPU spikes and response times change.

Amazon posted a strong praise for Rust, Go technology head: don't "pull" us!

Left: Go, Right: Rust

To solve this problem, Discord decided to try rewriting the service with Rust, which shows the results of the use. While the GC peak pattern is gone in Rust, the really striking difference is the magnitude of the change. Note that go and Rust have different units of measurement.

Rust versions are overall more than 10 times faster, and even the worst tail latency is reduced by a factor of 100. These are incredible improvements, and as servers become more responsive, fewer servers are needed, which means less energy is used. While Discord hasn't decided to start using Rust to reduce energy consumption, that's the impact.

Plus, Rust isn't the first efficient language. C has been around for a long time, but Rust was the first mainstream programming language to guarantee efficiency without sacrificing security. Of all high-risk security vulnerabilities written in C and C++, 70% are caused by memory insecurity. Rust provides efficiency, but doesn't make people feel like they're playing with fire.

In this regard, Cox pointed out that Discord's original post showed a chart of go servers and equivalent Rust servers. Rust has more predictable performance and avoids latency spikes like in Go, but their performance is roughly comparable.

Amazon posted a strong praise for Rust, Go technology head: don't "pull" us!

In the comparison chart in discord's original post, the purple line represents Go and the blue line represents Rust

Instead, in amazon posts, the Rust and Go charts show a timescale comparison of "ms" and "s." But the premise of this comparison is that the Rust server has made a major rewrite and uses new data structures and more memory.

"This is either a complete lack of understanding of Discord's post or a blatant lie." Cox believes that this comparison method is a good expression in an honest and fair situation, "but this is not the case with the AWS post." ”

However, Cox points out that Discord's post is fair. "It compares the Go server to the Rust server and plots the changes that the Rust server has changed after using the rewritten data structure and extra memory separately later in the article, and the AWS post misinterprets this."

At the same time, Discord's post also mentions Go 1.10, and Go 1.18 will be released soon. There were many improvements to the 8 versions over this period, reducing the number of very large heaps in the program or GC pauses for very many protocols (both of the Discord server). Therefore, using a recent version of Go will significantly reduce Discord latency spikes. "But Rust is still a good language for the server, and the team made a sound decision."

Cox didn't completely deny the post's views on Rust, but in Cox's opinion, Amazon had no need to add misleading statements about Go, "It looks shameful, Rust is enough to exist on its own." ”

Go, Rust controversy

Both languages originated in the same period. Go was conceived in 2007 and made public in November 2009, and Rust appeared a few months later in 2010, though Graydon hinted that Rust might have been conceived much earlier.

Go and Rust have a lot in common. Both are modern software languages designed to provide secure and scalable solutions to problems affecting software development. Both were also created in response to the problems encountered by existing languages at the time, especially those encountered by developers in terms of productivity, scalability, security, and concurrency. Therefore, the two are often considered to be in competition.

But there are also many differences between the two. Steve Francia, head of product and strategy for Google's Go programming language, believes that Go and Rust have similarities in terms of performance concurrency, scalability, and open source awareness, but there are different trade-offs between the two. In an article posted to thenewstack, Francia compares the differences between Go and Rust in detail.

In terms of performance, Go has excellent performance out of the box. By design, there are no buttons or joysticks in Go that can squeeze out more performance. Rust is designed to allow developers to squeeze every performance out of their code, so Rust is faster at the expense of added complexity.

In terms of adaptability, the advantage of Go's rapid iterations allows developers to quickly experiment with ideas and hone them on the working code that solves the task at hand. This is usually enough, and developers can free up time for other tasks. Rust, on the other hand, takes longer compilation times compared to Go, resulting in slower iteration times. This allows Go to work better in changing requirements scenarios with shorter turnaround times, and Rust to excel in implementation scenarios that have more time for more granular and efficient development.

In terms of ease of learning, Go is a more approachable language, and many teams are even able to use Go and put Go services/applications into production within a few weeks. Because of its complexity, Rust is considered a difficult language to learn, but it also brings higher performance to Rust.

When it comes to precise control, Rust has a big advantage. Rust gives developers more precise control over how they manage memory, how they use the machine's available resources, how they optimize their code, and how they develop solutions.

Therefore, Francia's advice is that Go is the right default option for most companies and developers, as Go is powerful, easy to adopt, and highly modular makes it ideal for situations with changing needs. As products mature and demand stabilizes, businesses may have the opportunity to reap significant benefits from marginal performance gains. In these cases, using Rust to maximize performance may be a good choice.

Conclusion

"In my opinion, rather than reading articles that see Go and Rust as zero-sum games, I prefer to focus on articles that see Go and Rust as complementary and work well together." Cox said at the end.

The battle over programming languages has never stopped, each language has a large number of adherents, and there is even a "chain of contempt", and the annual list of programming languages is also a hot spot for everyone to pay attention to. But programming languages are not incompatible, and developers need to learn to choose the language that suits them.

Related information:

https://aws.amazon.com/cn/blogs/opensource/sustainability-with-rust/

https://thenewstack.io/rust-vs-go-why-theyre-better-together/

https://twitter.com/_rsc/status/1496352332556161024

Read on