Facebook enhances C++ with parallel programming tool

Facebook's Folly Futures provides an easy way to do parallel programming in C++

Instagram uses Folly Futures to offer personalized recommendations for users

Instagram uses Folly Futures to offer personalized recommendations for users

Ever wondered how Facebook is able to assemble personalized news feeds, in real time, for any of its billion-plus users who may log in at any given moment? Now we know, because the company has just released the source code behind the magic.

Drawing from their considerable expertise running large workloads, Facebook engineers developed a framework, called Folly Futures, that allows programmers to easily break apart their C++ applications so they can run more quickly in parallel, or asynchronously.

The framework allowed Facebook to cut the average latency of its news feed by two-thirds, and significantly reduced the number of time-out errors that users see.

"Futures made it natural to express the asynchronous computation," Hans Fugal, a Facebook engineer who helped create the framework, said in a blog post.

"When developers have the tools to understand and express asynchrony better, they write lower-latency services that are easier to maintain," he wrote.

Facebook's Instagram service also uses the farmework, to improve performance and reduce the number of servers it needs for a service that recommends to users who they should follow.

The new tool tackles ones of the most difficult problems in computer programming, that of parallel computing.

Parallel computing allows multiple parts of a program to run simultaneously to speed performance. The practice can be fraught with difficulty, however, if many services within a program depend on each other to complete their jobs.

A service for rendering a Web page, for example, may need content from another service, such as a database, before it can complete its task. Until it gets the information, the entire program may stall.

"The result is wasted resources, reduced throughput, and increased latency (because requests are in a queue, waiting to be serviced)," Fugal wrote.

The programmer can work around this manually, through standard parallel programming practices, but the resulting code can quickly become a tangled mess, a condition sometimes referred to as callback hell.

"Traditional asynchronous code is more efficient than synchronous code, but it is not as easy to read," Fugal noted.

The latest release of the C++ programming language, version C++11, includes a capability called Futures that allows programmers to neatly program in parallel, so a program can continue to execute new work even as it awaits the completion of individual operations.

In essence, a "future" is a stub that can be held by part of a program until the results are returned by another operation, allowing the program to continue on to additional tasks.

Facebook's Futures, part of its Folly library of open source programming tools, provides a way to easily use C++ futures. It extends the generic C++11 futures capabilities to enhance readability of the code while maintaining compatibility of the C++ API (application programming interface). The development team used the Twitter Futures, written for the Scala language, as a point of reference.

Instagram used Folly Futures to create a set of recommendation services that can handle tens of thousands of queries per second and generate tens of millions of connections per day.

The services generate lists of additional Instagram accounts that users could follow, drawing from a pool of known friends, friends of friends, and popular accounts in the user's area.

"After moving to Futures, we had a performant system with clear, readable code," Instagram said. "Our services can fully exploit system resources and are more reliable and efficient."

Because of the restructuring of the code, CPU utilization of the suggested user service bounced to 90 percent from the 10 to 15 percent range. Better CPU utilization meant fewer copies of the program needed to be run at once, from 720 to 38, thus requiring fewer servers. Each program is capable of handling 800 requests per second, with an average latency of 40 milliseconds.

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 Joab_Jackson@idg.com

Join the Good Gear Guide newsletter!

Error: Please check your email address.

Tags Development toolsapplication developmentsoftwareFacebook

Our Back to Business guide highlights the best products for you to boost your productivity at home, on the road, at the office, or in the classroom.

Keep up with the latest tech news, reviews and previews by subscribing to the Good Gear Guide newsletter.

Joab Jackson

IDG News Service
Show Comments

Cool Tech

Crucial Ballistix Elite 32GB Kit (4 x 8GB) DDR4-3000 UDIMM

Learn more >

Gadgets & Things

Lexar® Professional 1000x microSDHC™/microSDXC™ UHS-II cards

Learn more >

Family Friendly

Lexar® JumpDrive® S57 USB 3.0 flash drive 

Learn more >

Stocking Stuffer

Plox Star Wars Death Star Levitating Bluetooth Speaker

Learn more >

Christmas Gift Guide

Click for more ›

Most Popular Reviews

Latest News Articles

Resources

GGG Evaluation Team

Kathy Cassidy

STYLISTIC Q702

First impression on unpacking the Q702 test unit was the solid feel and clean, minimalist styling.

Anthony Grifoni

STYLISTIC Q572

For work use, Microsoft Word and Excel programs pre-installed on the device are adequate for preparing short documents.

Steph Mundell

LIFEBOOK UH574

The Fujitsu LifeBook UH574 allowed for great mobility without being obnoxiously heavy or clunky. Its twelve hours of battery life did not disappoint.

Andrew Mitsi

STYLISTIC Q702

The screen was particularly good. It is bright and visible from most angles, however heat is an issue, particularly around the Windows button on the front, and on the back where the battery housing is located.

Simon Harriott

STYLISTIC Q702

My first impression after unboxing the Q702 is that it is a nice looking unit. Styling is somewhat minimalist but very effective. The tablet part, once detached, has a nice weight, and no buttons or switches are located in awkward or intrusive positions.

Featured Content

Latest Jobs

Don’t have an account? Sign up here

Don't have an account? Sign up now

Forgot password?