YouTube scales MySQL with Go code
YouTube's Vitess helps MySQL use less memory and run more efficiently
IDG News Service - 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.
- Social Media Education: The New Edge for Success Failure to train for social media will cost your business money. A recent report showed how digitally prepared companies can unlock up to...
- Social Media in Technology: A Unified Strategy for Success Find out how social media is sparking a new era of customer and industry-understanding in technology enterprises and how industry leaders are overcoming...
- How Network Connections Drive Web Application Performance Users around the globe, on all sorts of devices, expect Web applications to function as seamlessly as desktop applications. This paper discusses the...
- 5 Customers Deliver Virtual Desktops and Apps to Empower a Modern Workforce Learn how Citrix solutions helped 5 companies realize the full value of desktop virtualization through a project-by-project approach based on key business priorities.
- What Does it Take to Deliver a Superior Customer Experience? The Two Top-Rated Online Retailers, B&H Photo and Crutchfield Electronics, Share Their Secrets Discuss practical CX tools and service methods such as contact center agents and the use of realtime speech analytics to help contact center...
- Keep Servers Up and Running and Attackers in the Dark An SSL/TLS handshake requires at least 10 times more processing power on a server than on the client. SSL renegotiation attacks can readily... All Internet White Papers | Webcasts
Our new bimonthly Internet of Things newsletter helps you keep pace with the rapidly evolving technologies, trends and developments related to the IoT. Subscribe now and stay up to date!