2020年4月21日火曜日

Rust Improves Processing Speed: Go to Rust Language Change, Gamer Chat App Discord's Challenges

https://www.atmarkit.co.jp/ait/articles/2002/10/news038.html

Shared.



Discord, a chat application for gamers, has revealed issues with one of its underlying services, Read States, not being able to speed up sufficiently. The development team attempted to respond by further improving the existing code. However, when reimplemented in the Rust language, the performance improved even before the optimization was applied. I wonder why. The development team explains why.Published February 10, 2020 at 11:40 am The Read States service we were implementing in Go didn't adequately address the requirement for high speed. Although it was running fast on average, the average response time increased rapidly every few minutes, which detracted from the user experience. Upon investigation, it was found that this was due to Go's core functionality, the memory model and garbage collector (GC).



 There are billions of read states in Discord, and the data structure that Discord uses to store read state information is called "Read State" below. This is because you need one Read State for each user and channel combination. Each Read State has a number of counters. For example, one of the counters represents the number of mentions a user has in a channel.

 Updating these counters piecemeal would be inconsistent. I have to update Atomic. It must be reset to 0 even more frequently.

 Each Read States server has an LRU (Least Recently Used) cache of Read States in order to update the atomic counter faster. Each cache contains millions of users and tens of millions of Read States. And the cache is updated hundreds of thousands of times per second.

 To ensure data persistence, Discord complements the cache with a cluster of Apache Cassandra, a distributed database management system. Read State is committed to the database when the cache key is evicted (to remove unnecessary data). In addition, I always put a 30-second database commit when I update Read State. Thus, the database is written tens of thousands of times per second.

Why is Rust so fast?
 Rust doesn't need a garbage collection. That's why the company wanted to implement the Read States service in Rust; with Rust, you wouldn't see the spike in average response time that occurred when implementing it in Go.

 Rust takes a relatively unique approach to memory management that embraces the idea of "memory ownership". Since memory is proprietary, it can track read and write permissions for a memory area, and release the memory area as soon as it is no longer needed; since Rust enforces memory rules at compile time, memory bugs are almost impossible; there is no need to track the memory area manually like C, and the compiler takes care of everything.

Although "Asynchronous Rust" was less complete, the community helped
 At the time of the reimplementation of the Read States service, the stable version of Rust did not have enough support for asynchronous Rust. But for network services, asynchronous programming is a must. There were some community libraries with asynchronous Rust enabled, but they required complicated procedures and error messages were very difficult to understand when a problem occurred.

 Fortunately, the Rust team has been working diligently to make asynchronous programming easier, and an unstable version with enhanced asynchronous programming capabilities is now available on Rust's Nightly channel.

 Discord implemented a nightly release and worked with the Rust team to address issues as they arose. As a result, at present, the stable version of Rust supports asynchronous Rust.

Translated with www.DeepL.com/Translator (free version)

0 コメント:

コメントを投稿