开发者必看,Facebook高性能基础库folly开源了
2012-06-03 20:43
423 查看
folly是facebook重构的高效底层函数集,今天得知已经开源:https://github.com/facebook/folly/blob/master/folly/docs/Overview.md
其编码及相关算法实现都很值得学习,特别是优化底层服务器的同学。做优化的同学可以参考其相关功能进行函数优化。本博也会陆续将相关的移植和学习收获发出来供大家参考。
folly的本地下载地址 :/Files/inteliot/facebook-folly-27494a2.zip
Performance concerns permeate much of Folly, sometimes leading to designs that are more idiosyncratic than they would otherwise be (see e.g.
All symbols are defined in the top-level namespace
The directory structure is flat (mimicking the namespace structure), i.e. we don't have an elaborate directory hierarchy (it is possible this will change in future versions). The subdirectory
The
Simple arena for memory allocation: multiple allocations get freed all at once. With threaded version.
High-performance atomic hash map with almost lock-free operation.
A small framework for benchmarking code. Client code registers benchmarks, optionally with an argument that dictates the scale of the benchmark (iterations, working set size etc). The framework runs benchmarks (subject to a command-line flag) and produces formatted output with timing information.
Various bit manipulation utilities optimized for speed.
Bit-twiddling functions that wrap the ffsl(l) primitives in a uniform interface.
An implementation of the structure described in A Provably Correct Scalable Concurrent Skip List by Herlihy et al.
A variety of data conversion routines (notably to and from string), optimized for speed and safety.
Similar to
Dynamically-typed object, created with JSON objects in mind.
Endian conversion primitives.
Escapes a string in C style.
Wrapper around the
A drop-in implementation of
A mostly drop-in implementation of
Pseudo-statements (implemented as macros) for iteration.
Python-style formatting utilities.
Group Varint encoding for 32-bit values.
Various popular hash function implementations.
A simple class for collecting histogram data.
Convenience type definitions for using
JSON serializer and deserializer. Uses
Wrappers around
Memory allocation helpers, particularly when using jemalloc.
Helpers for finding items in associative containers (such as
A highly specialized data structure consisting of a pointer, a 1-bit spin lock, and a 15-bit integral, all inside one 64-bit word.
Necessarily evil stuff.
Pretty-printer for numbers that appends suffixes of unit used: bytes (kb, MB, ...), metric suffixes (k, M, G, ...), and time (s, ms, us, ns, ...).
Lock free single-reader, single-writer queue.
Defines only one function---
Boost-style range facility and the
Fast and compact reader-writer spin lock.
C++11 incarnation of the old ScopeGuard idiom.
Very small spin locks (1 byte and 1 bit).
Vector with the small buffer optimization and an ptional embedded
Collections similar to
STL allocator wrapping a simple allocate/deallocate interface.
String utilities that connect
High-level synchronization library.
Demangling and errno utilities.
High-performance atomic increment using thread caching.
Improved thread local storage for non-trivial types.
Queue with per-item timeout.
Type traits that complement those defined in the standard C++11 header
Defines the
其编码及相关算法实现都很值得学习,特别是优化底层服务器的同学。做优化的同学可以参考其相关功能进行函数优化。本博也会陆续将相关的移植和学习收获发出来供大家参考。
folly的本地下载地址 :/Files/inteliot/facebook-folly-27494a2.zip
Introduction
Folly (acronymed loosely after Facebook Open Source Library) is a library of C++11 components designed with practicality and efficiency in mind. It complements (as opposed to competing against) offerings such as Boost and of coursestd. In fact, we embark on defining our own component only when something we need is either not available, or does not meet the needed performance profile.
Performance concerns permeate much of Folly, sometimes leading to designs that are more idiosyncratic than they would otherwise be (see e.g.
PackedSyncPtr.h,
SmallLocks.h). Good performance at large scale is a unifying theme in all of Folly.
Logical Design
Folly is a collection of relatively independent components, some as simple as a few symbols. There is no restriction on internal dependencies, meaning that a given folly module may use any other folly components.All symbols are defined in the top-level namespace
folly, except of course macros. Macro names are ALL_UPPERCASE. Namespace
follydefines other internal namespaces such as
internalor
detail. User code should not depend on symbols in those namespaces.
Physical Design
At the top level Folly uses the classic "stuttering" schemefolly/follyused by Boost and others. The first directory serves as an installation root of the library (with possible versioning a la
folly-1.0/), and the second is to distinguish the library when including files, e.g.
#include "folly/FBString.h".
The directory structure is flat (mimicking the namespace structure), i.e. we don't have an elaborate directory hierarchy (it is possible this will change in future versions). The subdirectory
experimentalcontains files that are used inside folly and possibly at Facebook but not considered stable enough for client use. Your code should not use files in
folly/experimentallest it may break when you update Folly.
The
folly/folly/testsubdirectory includes the unittests for all components, usually named
ComponentXyzTest.cppfor each
ComponentXyz.*. The
folly/folly/docsdirectory contains documentation.
Compatibility
Currently,follyhas been tested on gcc 4.6 on 64-bit installations of Fedora 17, Ubuntu 12.04, and Debian wheezy. It might work unmodified on other 64-bit Linux platforms.
Components
Below is a list of Folly components in alphabetical order, along with a brief description of each.Arena.h
, ThreadCachedArena.h
Simple arena for memory allocation: multiple allocations get freed all at once. With threaded version.AtomicHashMap.h
, AtomicHashArray.h
High-performance atomic hash map with almost lock-free operation.Benchmark.h
A small framework for benchmarking code. Client code registers benchmarks, optionally with an argument that dictates the scale of the benchmark (iterations, working set size etc). The framework runs benchmarks (subject to a command-line flag) and produces formatted output with timing information.Bits.h
Various bit manipulation utilities optimized for speed.Bits.h
Bit-twiddling functions that wrap the ffsl(l) primitives in a uniform interface.ConcurrentSkipList.h
An implementation of the structure described in A Provably Correct Scalable Concurrent Skip List by Herlihy et al.Conv.h
A variety of data conversion routines (notably to and from string), optimized for speed and safety.DiscriminatedPtr.h
Similar to boost::variant, but restricted to pointers only. Uses the highest-order unused 16 bits in a pointer as discriminator. So
sizeof(DiscriminatedPtr<int, string, Widget>) == sizeof(void*).
dynamic.h
Dynamically-typed object, created with JSON objects in mind.Endian.h
Endian conversion primitives.Escape.h
Escapes a string in C style.eventfd.h
Wrapper around the eventfdsystem call.
FBString.h
A drop-in implementation of std::stringwith a variety of optimizations.
FBVector.h
A mostly drop-in implementation of std::vectorwith a variety of optimizations.
Foreach.h
Pseudo-statements (implemented as macros) for iteration.Format.h
Python-style formatting utilities.GroupVarint.h
Group Varint encoding for 32-bit values.Hash.h
Various popular hash function implementations.Histogram.h
A simple class for collecting histogram data.IntrusiveList.h
Convenience type definitions for using boost::intrusive_list.
json.h
JSON serializer and deserializer. Uses dynamic.h.
Likely.h
Wrappers around __builtin_expect.
Malloc.h
Memory allocation helpers, particularly when using jemalloc.MapUtil.h
Helpers for finding items in associative containers (such as std::mapand
std::unordered_map).
PackedSyncPtr.h
A highly specialized data structure consisting of a pointer, a 1-bit spin lock, and a 15-bit integral, all inside one 64-bit word.Preprocessor.h
Necessarily evil stuff.PrettyPrint.h
Pretty-printer for numbers that appends suffixes of unit used: bytes (kb, MB, ...), metric suffixes (k, M, G, ...), and time (s, ms, us, ns, ...).ProducerConsumerQueue.h
Lock free single-reader, single-writer queue.Random.h
Defines only one function---randomNumberSeed().
Range.h
Boost-style range facility and the StringPiecespecialization.
RWSpinLock.h
Fast and compact reader-writer spin lock.ScopeGuard.h
C++11 incarnation of the old ScopeGuard idiom.SmallLocks.h
Very small spin locks (1 byte and 1 bit).small_vector.h
Vector with the small buffer optimization and an ptional embedded PicoSpinLock.
sorted_vector_types.h
Collections similar to std::mapbut implemented as sorted vectors.
StlAllocator.h
STL allocator wrapping a simple allocate/deallocate interface.String.h
String utilities that connect folly::fbstringwith
std::string.
Synchronized.h
High-level synchronization library.System.h
Demangling and errno utilities.ThreadCachedInt.h
High-performance atomic increment using thread caching.ThreadLocal.h
Improved thread local storage for non-trivial types.TimeoutQueue.h
Queue with per-item timeout.Traits.h
Type traits that complement those defined in the standard C++11 header <traits>.
Unicode.h
Defines the codePointToUtf8function.
相关文章推荐
- libPhenom:Facebook开源的高性能C语言并发编程框架
- 开源博客QBlog开发者视频教程:开篇-开发基础配置与系统运行(一)
- Facebook 开源安卓版 React Native,开发者可将相同代码用于网页和 iOS 应用开发
- Facebook开源Caffe2深度学习框架:开发者可快速训练和迭代AI模型
- 开源博客QBlog开发者视频教程:开篇-开发基础配置与系统运行(一)
- ASP.NET开源博客QBlog开发者视频教程:开篇-开发基础配置与系统运行(一)
- 开源博客QBlog开发者视频教程:开篇-开发基础配置与系统运行(一)
- libPhenom:Facebook开源的高性能C语言并发编程框架
- 开源博客QBlog开发者视频教程:开篇-开发基础配置与系统运行(一)
- 开源博客QBlog开发者视频教程:开篇-开发基础配置与系统运行(一)
- Android开发者应该深入学习的10个开源应用项目
- 开源Math.NET基础数学类库使用(17)C#计算矩阵条件数
- 开源安装包管理工具yum的开发者Seth Vidal因车祸去世
- Facebook开源检测工具包 Detectron (by Caffe2)
- <转> Android开发者应该深入学习的10个开源应用项目
- Facebook开发者创建APP生成KeyHash
- 校内网开放平台再开源 试验让开发者赢利
- ATC, Facebook开源模拟网络环境的工具
- 10个开源项目Android开发者掌握技术必学
- [开源]KJFramework.Message 高性能二进制消息框架 - 多元素数组的高性能优化