Rust has been selected to reduce costs and increase efficiency again! Rust replaces Python, Amazon C

Mondo Finance Updated on 2024-02-01

A magical combination has appeared! Rust and serverless can be a big savings over using Python!

It's no secret that lambda functions and large runtimes are a terrible combination, as cold starts are slower and memory requirements are higher compared to native**. On the other hand, many developers will be more efficient using J**A and Python than they are using systems languages such as Rust.

Now, however, you don't need to rewrite the entire lambda function (pyhton) in rust to really "reduce costs and increase efficiency".

Merdler Kr**Itz, an engineering lead at CloudEx, a cloud consulting firm, gave an example of a lambda function that uses Python to list S3 (Simple Storage Service) buckets. The AWS SDK Boto3 for Python has proven to be too bloated, and there are huge benefits to be gained in terms of cost and performance by replacing functions that require Boto3 with Rust - even though Python is still being used for something else.

The key to replacing Python with Rust is PYO3, which provides Rust bindings for Python. Properties in rust expose functions as standard python interfaces.

As a result, in the example presented by Merdler Kr**Itz, the cold start was three times faster and the memory requirements were much lower. For 1GB of RAM, Rust and Boto3** have similar performance, but for 256MB of RAM, the enhanced version of Rust still performs well, while the other does not.

Cost-effectiveness of using rust in lambda: an example on re:invent.

Especially on serverless platforms, reducing the amount of computing resources required can reduce costs. "Rust is cheaper than Python on average, probably 1 3 to 1 4 of the latter," he claims.

At Re:Invent, AWS also announced that its SDK for Rust is ready for production. Earlier last November, the cloud giant added support for Amazon Linux 2023 to Lambda based on "minimal container images", and said that one of its key uses is "when using languages compiled to native**, such as Go or Rust." ”

Unofficial support for AWS services in Rust has been around since at least 2015, when Matthew Mayer and Anthony Dimarco were working on Rust 1Shortly after the release of 0, a standalone project called Rusoto was launched, with goals that included learning Rust. According to the rust crate repository cratesIO's statistics, Rusoto's ** volume has exceeded 11 million times.

The first alpha of the AWS Rust SDK was launched in 2021 by Iliana Etaoin, who was at AWS at the time, and she was a co-maintainer of Rusoto.

According to the introduction, the official Rust SDK now supports more than 300 AWS services and "supports modern Rust language features such as asynchronous waits, non-blocking IOs, and builders."

AWS Lambda also has an experimental Rust runtime that simplifies running in Rust and includes crates that support Lambda events, extensions, and the Lambda Runtime API. A related project called Cargo Lambda supports local development and testing with the Lambda emulator, as well as cross-compilation for Linux when developing on Windows or macOS, with the option of arm64 and x86-64 regardless of what the developer is running on their PC. Using rust to build lambda, Amazon officially gave detailed documentation.

Of course, experimental ** is not used in production, so it's too early to use rust on lambdas. For now, though, it can be seen that the payoff will be huge.

The power of example is endless. According to the feedback of Amazon internal employees on a workplace social platform, "everyone uses Rust here", and some netizens also pointed out that Jon Gjergeset, the leader of the Rust compiler team, also works at Amazon.

The employee even made a judgment: sooner or later, Rust will replace C++.

What are the scenarios where rust is used?A simple answer is all scenarios that use C++.

However, as far as the partial replacement of Python announced by Amazon this time, there is another scenario where Python is increasingly at risk of being replaced.

After entering the context of "large model application development", the original "python+docker" machine learning development framework is facing serious challenges.

When building machine learning applications, more people think of python + docker, but when the time comes to the "big model era", it seems out of place to build large model applications based on this combination, and the performance of python and the cold start problem of docker are doomed to the fact that when dealing with large data sets or complex models that require a lot of computation, it is unlikely to become the mainstream choice in this field.

On the one hand, Python is an interpreted language, which has a slow compilation speed and serious maintenance problems. On the other hand, Docker is increasingly exposed to issues such as disk space consumption, hardware accelerator support, portability, and security dependencies.

Based on this, some people in the industry believe that Rust+Wasm is more likely to replace Python+Docker and become the main scenario for building infrastructure in the LLM ecosystem. This has to make people think of Musk's speculation that "AGI will be built on Rust".

Editor's search image Speaking of Rust alone, why is Rust sought after as a programming language in the agi era?

First, compile extremely fast: Rust is a compiled language known for its blazing fast performance. When combined with WebAssembly, a binary instruction format for stack-based virtual machines, the combination promises to provide unmatched execution speeds.

Second, memory safety: One of the standout features of Rust is its emphasis on memory safety without sacrificing performance. This ensures that the application is fast and secure.

Then, concurrency: Rust's approach to concurrency is unique. It ensures that data contention (one of the most common and challenging mistakes in concurrent systems) is caught at compile time. This means that developers can write concurrency without worrying about introducing runtime errors that are difficult to detect.

Also, an expressive type system: Rust has a powerful and expressive type system. Not only does the system help catch errors at compile time, but it also allows developers to express their intentions in a clear and concise manner.

At the same time, modern package management: Cargo, Rust's package manager, simplifies the process of managing dependencies, building projects, and even publishing libraries. A tool praised for its ease of use and efficiency.

Finally, the fast-growing ecosystem: The Rust ecosystem is thriving. Libraries like "ndarray", "llm", "candle", and "burn" demonstrate the ability of the large model-related community to actively participate in the development of LLM applications that extend Rust.

So why do you need webassembly?

Unlike most "modern programming languages", one of the highlights of Rust is that it can be compiled directly into machine code, without the need for an intermediate "runtime". However, in many scenarios, such as browsers, cloud native, edge devices, etc., it is not allowed to run machine code directly. Even proficient Rust lacks a runtime to match.

In practice, one will find that WebAssembly is one of the first choices for the Rust runtime. Observant people may also notice that the Rust compiler also adds a target for the Wasm platform. The two are a match made in heaven.

There is a clear difference between domestic development and foreign development.

There are many fewer large-scale underlying projects in the domestic software industry than in foreign countries, and the development direction is mainly in the upper-level logic of changing demand.

In the past thirty or forty years, developers have focused more on the business application layer, doing the sorting and stacking of functional modules, while the research of the bottom ** is more like a ball of yarn.

However, we are also slowly seeing that new development themes are coming: the business side is more concerned about security and reliability, more concerned about whether the dependence of the ** chain is sustainable, and more concerned about whether it will be stuck. For example, last year, Mark Russinovich, the CTO of Microsoft Azure, posted a tweet that was hotly searched in the tech world, and he wanted to abandon C++ and move to Rust.

Interestingly, 70% of Microsoft's common vulnerabilities and exposures are related to memory security issues. And, despite the efforts that have taken place to fix these issues, they are still soaring.

To that end, the Microsoft Security Response Center has launched a program for a programming language for security systems, intending to migrate their project to a Rust project. Even the Windows kernel, which everyone knows later, began to be rewritten in Rust.

So we see that many well-known companies are also investing heavily in Rust, such as foreign companies such as Microsoft and Google have become one of the platinum sponsors of Rust, AWS has directly recruited members of the official Rust team to start a talent war, Meta (formerly Facebook) officially announced Rust as a language supported by its server, and so on.

For another example, domestic technology companies such as Huawei and ByteDance have cultivated Rust teams internally and promoted the implementation of Rust, PingCap has adopted Rust to implement TikV, and many star start-ups such as Datan Technology and Haizhixingtu have directly chosen Rust as the main language of their products.

According to the content of the speech of Wu Di, the head of ByteDance Volo, there are additions and deletions.

However, there is a point of view that Rust will not be used on a large scale in China, even if it is to be used, it should start from major cloud vendors, and it is a variety of underlying projects, and the more mainstream language of cloud vendors is Golang, because the development efficiency of Golang is quite high, which is very in line with the business logic of domestic cloud vendors. Luckily, ByteDance is moving from Golang to Rust.

The rise of a language is often the solution to the pain points of the times. PHP solves the problem of rapid construction of portals, Python lowers the threshold of programming, J**A solves the application development needs of the mobile era, and C C++ has made contributions more than 40 years ago at the bottom of the system.

The same goes for Rust. Unlike most "modern programming languages", Rust was chosen in a new context that emphasizes security, speed, and reliability at the bottom. Counting from the 15 years of stable, Rust has indeed come a short time. It has been the most respected language among developers for 8 years in a row!

The 2023 Stackoverflow Developer Survey shows that 85% of developers who use Rust want to use it again next year.

Finally, a little tidbit, 2023 has passed, what is it like to apply and develop Rust in daily life?

We have selected these four attitudes, all of which should be a glimpse of the current situation of domestic Rust developers, and it can be seen that it is also a process of upgrading and fighting monsters

Full-time Rust developers: I was quite happy to do Rust full-time at first, but within two months, the passion was gone, and I was really choking every day, and now it has become a "garbage rust" every day. 」

Leader of the Rust project: It is recommended to train yourself, and don't listen to the Internet about how hard it is to get started with Rust. As long as there is one person in the company who knows Rust very well, everyone else can get up to speed quickly. 」

Ashorer: If you don't make a complicated Generic with three or four lifetimes, you usually won't have a problem. The handwriting business on Rust only takes a month, and it takes experience to write bells and whistles. 」

Someone who has used Rust for more than 8 years: Most of the newcomers I bring have a language foundation such as J**A or C, and they can basically get started in a month, algorithms, asynchronous and multi-threading are no problem, and even liberal arts students turn to write Rust, they don't think it's difficult. 」

Related Pages