YouTube scales MySQL with Go code
YouTube engineers are developing a set of software, called Vitess, that will help open-source MySQL databases work more efficiently in very large-scale production environments. To write the code, they are using Google’s programming language Go.
YouTube already uses one Vitess component, called Vtocc, to help serve videos to all of the service’s 800 million monthly users. Google acquired YouTube in 2006.
Vtocc has “been very steady, and it has all the necessary tools for you to use in a production environment,” said YouTube architect Sugu Sougoumarane, who, along with YouTube engineer Mike Solomon, discussed Vitess at the Usenix LISA (Large Installation System Administration) conference, held this week in San Diego.
That Vitess is written in Go could help validate the idea that this relatively new programming language could be used in large-scale production environments. Google introduced version 1 of Go in March.
YouTube serves more than 4 billion hours of video each month. About 72 hours of video are uploaded to the service every minute. While YouTube stores all its videos directly on a file system, it uses MySQL to store all the metadata needed to serve each video, such as user preferences, advertising information, country customizations and other needed bits of information.
YouTube likes using MySQL for its reliability, said Solomon, one of the engineers who originally built the service. It has quirks, but those quirks are well-known and can be mitigated fairly easily, he said. However, MySQL also has issues with scaling — at least scaling to accommodate a service as large as YouTube’s.
“The major problem with MySQL is that once you get to a certain point [of usage], you spend a lot of time managing hardware and how many instances you have,” Solomon said. “We want to automate that chunk. We want to take every action that is complicated and error prone and make it heal itself.”
MySQL also is not very efficient when used in a large deployment. Typically, each connection to MySQL requires its own thread on the server. This approach is not feasible at the scale of YouTube’s operations, however. “Running tens of thousands of connections is not really viable,” Solomon said.
The company’s engineers, however, have been reluctant to try to change the core MySQL code itself, noting that making changes to the complex and somewhat difficult-to-understand code can often result in unanticipated effects. “It is not straightforward. Just when you think you know what you are doing, that’s when you start getting in trouble,” Solomon said.
So Vitess was created to run in conjunction with MySQL to offer additional management capabilities. The Vtocc component, for example, consolidates thousands of incoming SQL queries into a smaller number of batches so MySQL can take fewer resources fulfilling these requests. Vtocc also parses queries so they can be executed more efficiently, and reduces the work caused by duplicate queries by reusing the results from one query to satisfy the other identical requests.
Using Go has allowed YouTube developers to be more productive than they would have been using a more traditional language, Sougoumarane said.
Go code compiles quickly, he said. The 30,000 lines of code in Vitess can be compiled into binaries in about 30 seconds. And, thanks to a rich set of libraries, many tasks do not require that much programming. For instance, Sougoumarane wrote a 105-line routine that periodically trims log files, functionality that couldn’t have been written in as few lines by using C or C++.
“That’s how expressive Go is,” Sougoumarane said. “The language features are well-thought-out. They help you compose things in a much more elegant way than traditional languages.” Sougoumarane also praised Go’s concurrency support, vital for use in multicore processors. “You don’t have to worry about managing threads. Go manages them for you,” he said.
The language also has some downsides, too, Sougoumarane admitted. Error handling could be improved, for instance. Scheduling and garbage collection could use some work as well.
Solomon said that, over time, Vitess will take on additional duties, such as database replication and automatic sharding, so a database can grow across multiple servers with no intervention from administrators.
Joab Jackson covers enterprise software and general technology breaking news for The IDG News Service. Follow Joab on Twitter at @Joab_Jackson. Joab’s e-mail address is [email protected]