Under the Hood: Building and open-sourcing fbthrift

Visit the post for more.

Dave Watson
6 min readintermediate
--
View Original

Overview

The article discusses the evolution of Thrift at Facebook, highlighting the enhancements made to improve performance and functionality, leading to the release of fbthrift as an open-source project. Key improvements include the introduction of the THeader protocol and the use of folly's IOBuf for better memory management and asynchronous processing.

What You'll Learn

1

How to implement the THeader protocol for per-request features in Thrift

2

Why using folly's IOBuf improves memory management in Thrift

3

When to apply transport compression in Thrift services

Prerequisites & Requirements

  • Understanding of RPC frameworks and serialization concepts
  • Familiarity with GitHub for accessing fbthrift(optional)

Key Questions Answered

What improvements were made in fbthrift compared to the original Thrift?
Fbthrift introduces significant improvements such as the THeader protocol for adding per-request features and the use of folly's IOBuf for better memory management. These enhancements address performance issues and allow service owners to implement features without altering core libraries, ensuring backward compatibility.
How does fbthrift handle asynchronous workloads?
Fbthrift improves asynchronous workload performance by utilizing a new transport based on folly's IOBuf, allowing for out-of-order responses and better memory management. This change reduces latency and enhances the overall efficiency of service requests, particularly in complex service architectures.
What are the performance benefits of using fbthrift?
Services that transitioned to the new cpp2 generated code in fbthrift have reported up to a 50% decrease in latency and significant reductions in memory footprint. This demonstrates the effectiveness of the architectural changes made in fbthrift for high-performance applications.

Key Statistics & Figures

Latency reduction
up to 50%
Reported by services that transitioned to the new cpp2 generated code in fbthrift.

Technologies & Tools

Backend
Thrift
A cross-language framework for handling RPC, serialization, and server creation.
Library
Folly
Used for the IOBuf class to improve memory management in fbthrift.
Memory Allocator
Jemalloc
Used to allocate constant-sized buffers to enhance performance.

Key Actionable Insights

1
Implement the THeader protocol to enhance your Thrift services with per-request features.
This allows for greater flexibility in handling requests without modifying core libraries, making it easier to adapt to changing service requirements.
2
Utilize folly's IOBuf for memory management to improve performance in asynchronous processing.
This approach minimizes memory allocation overhead and can lead to significant latency improvements in high-load environments.
3
Consider dynamic compression for service requests based on message size to optimize performance.
By compressing larger messages while avoiding unnecessary compression for in-rack requests, you can reduce CPU usage and improve response times.

Common Pitfalls

1
Reinventing features like transport compression and authentication can lead to wasted resources.
This often occurs when teams do not leverage existing frameworks effectively, resulting in duplicated efforts and inconsistent implementations across services.

Related Concepts

Rpc Frameworks
Serialization Techniques
Performance Optimization Strategies