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 newsletter!

Or

Sign up to gain exclusive access to email subscriptions, event invitations, competitions, giveaways, and much more.

Membership is free, and your security and privacy remain protected. View our privacy policy before signing up.

Error: Please check your email address.

Tags Facebooksoftwareapplication developmentDevelopment tools

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

Toys for Boys

Family Friendly

Stocking Stuffer

SmartLens - Clip on Phone Camera Lens Set of 3

Learn more >

Christmas Gift Guide

Click for more ›

Brand Post

Bitdefender 2019

This Holiday Season, protect yourself and your loved ones with the best. Buy now for Holiday Savings!

Most Popular Reviews

Latest Articles

Resources

PCW Evaluation Team

Aysha Strobbe

Microsoft Office 365/HP Spectre x360

Microsoft Office continues to make a student’s life that little bit easier by offering reliable, easy to use, time-saving functionality, while continuing to develop new features that further enhance what is already a formidable collection of applications

Michael Hargreaves

Microsoft Office 365/Dell XPS 15 2-in-1

I’d recommend a Dell XPS 15 2-in-1 and the new Windows 10 to anyone who needs to get serious work done (before you kick back on your couch with your favourite Netflix show.)

Maryellen Rose George

Brother PT-P750W

It’s useful for office tasks as well as pragmatic labelling of equipment and storage – just don’t get too excited and label everything in sight!

Cathy Giles

Brother MFC-L8900CDW

The Brother MFC-L8900CDW is an absolute stand out. I struggle to fault it.

Luke Hill

MSI GT75 TITAN

I need power and lots of it. As a Front End Web developer anything less just won’t cut it which is why the MSI GT75 is an outstanding laptop for me. It’s a sleek and futuristic looking, high quality, beast that has a touch of sci-fi flare about it.

Emily Tyson

MSI GE63 Raider

If you’re looking to invest in your next work horse laptop for work or home use, you can’t go wrong with the MSI GE63.

Featured Content

Don’t have an account? Sign up here

Don't have an account? Sign up now

Forgot password?