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 PC World 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

Essentials

Microsoft L5V-00027 Sculpt Ergonomic Keyboard Desktop

Learn more >

Lexar® JumpDrive® S57 USB 3.0 flash drive

Learn more >

Mobile

Lexar® JumpDrive® S45 USB 3.0 flash drive 

Learn more >

Exec

Audio-Technica ATH-ANC70 Noise Cancelling Headphones

Learn more >

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

Learn more >

Lexar® JumpDrive® C20c USB Type-C flash drive 

Learn more >

HD Pan/Tilt Wi-Fi Camera with Night Vision NC450

Learn more >

Budget

Back To Business Guide

Click for more ›

Most Popular Reviews

Latest News Articles

Resources

PCW Evaluation Team

Azadeh Williams

HP OfficeJet Pro 8730

A smarter way to print for busy small business owners, combining speedy printing with scanning and copying, making it easier to produce high quality documents and images at a touch of a button.

Andrew Grant

HP OfficeJet Pro 8730

I've had a multifunction printer in the office going on 10 years now. It was a neat bit of kit back in the day -- print, copy, scan, fax -- when printing over WiFi felt a bit like magic. It’s seen better days though and an upgrade’s well overdue. This HP OfficeJet Pro 8730 looks like it ticks all the same boxes: print, copy, scan, and fax. (Really? Does anyone fax anything any more? I guess it's good to know the facility’s there, just in case.) Printing over WiFi is more-or- less standard these days.

Ed Dawson

HP OfficeJet Pro 8730

As a freelance writer who is always on the go, I like my technology to be both efficient and effective so I can do my job well. The HP OfficeJet Pro 8730 Inkjet Printer ticks all the boxes in terms of form factor, performance and user interface.

Michael Hargreaves

Windows 10 for Business / Dell XPS 13

I’d happily recommend this touchscreen laptop and Windows 10 as a great way to get serious work done at a desk or on the road.

Aysha Strobbe

Windows 10 / HP Spectre x360

Ultimately, I think the Windows 10 environment is excellent for me as it caters for so many different uses. The inclusion of the Xbox app is also great for when you need some downtime too!

Mark Escubio

Windows 10 / Lenovo Yoga 910

For me, the Xbox Play Anywhere is a great new feature as it allows you to play your current Xbox games with higher resolutions and better graphics without forking out extra cash for another copy. Although available titles are still scarce, but I’m sure it will grow in time.

Featured Content

Latest Jobs

Don’t have an account? Sign up here

Don't have an account? Sign up now

Forgot password?