Skip to content

Commit 72f27b5

Browse files
byrnedjmeta-codesync[bot]
authored andcommitted
Example CacheLib with Proxygen (#416)
Summary: For some benchmarking we like to have the network stack included - here is a simple example of adding CacheLib on top of proxygen for receiving data via HTTP request. ## Quick Setup (assumes dependencies live at CacheLib/opt) ### Build and run ``` getdeps.py install-system-deps cachelib getdeps.py build --allow-system-packages cachelib getdeps.py build --allow-system-packages proxygen ./build.sh ./build/proxygen_cache ``` ### PUT a value `curl -X PUT --data-binary 'hello world' http://localhost:8111/cache/greeting -i` ### GET it back `curl http://localhost:8111/cache/greeting -i` ### DELETE it `curl -X DELETE http://localhost:8111/cache/greeting -i` Pull Request resolved: #416 Test Plan: Imported from GitHub, without a `Test Plan:` line. ``` getdeps.py install-system-deps cachelib getdeps.py build --allow-system-packages cachelib getdeps.py build --allow-system-packages proxygen ./example/proxygen_cache/build.sh /data/users/juwin/scratch/homeZjuwinZCacheLib/fbcode_builder_getdeps/installed/cachelib/usr/local/lib/cmake:/data/users/juwin/scratch/homeZjuwinZCacheLib/fbcode_builder_getdeps/installed/proxygen/usr/local/lib/cmake/proxygen:/data/users/juwin/scratch/homeZjuwinZCacheLib/fbcode_builder_getdeps/installed/cachelib/usr/local/lib64/cmake:/data/users/juwin/scratch/homeZjuwinZCacheLib/fbcode_builder_getdeps/installed/proxygen/usr/local/lib64/cmake/proxygen:/data/users/juwin/scratch/homeZjuwinZCacheLib/fbcode_builder_getdeps/installed/cachelib/usr/local/lib:/data/users/juwin/scratch/homeZjuwinZCacheLib/fbcode_builder_getdeps/installed/cachelib/usr/local/lib64:/data/users/juwin/scratch/homeZjuwinZCacheLib/fbcode_builder_getdeps/installed/cachelib/usr/local:/data/users/juwin/scratch/homeZjuwinZCacheLib/fbcode_builder_getdeps/installed/:/data/users/juwin/scratch/homeZjuwinZCacheLib/fbcode_builder_getdeps/installed/proxygen/usr/local: -- Found Boost: /data/users/juwin/scratch/homeZjuwinZCacheLib/fbcode_builder_getdeps/installed/boost-3q1puqWKBVvE03fZboaAfiTqx8sfrdLPSNiGTo7FTQU/lib/cmake/Boost-1.83.0/BoostConfig.cmake (found suitable version "1.83.0", minimum required is "1.51.0") found components: context filesystem program_options regex system thread -- Found folly: /data/users/juwin/scratch/homeZjuwinZCacheLib/fbcode_builder_getdeps/installed/folly -- Found folly: /data/users/juwin/scratch/homeZjuwinZCacheLib/fbcode_builder_getdeps/installed/folly -- Found fizz: /data/users/juwin/scratch/homeZjuwinZCacheLib/fbcode_builder_getdeps/installed/liboqs-RS3Wq0UEy2BDdhQeFw1Q9VKrvJJ9dfECMDxnYEI_vRo -- Found wangle: /data/users/juwin/scratch/homeZjuwinZCacheLib/fbcode_builder_getdeps/installed/wangle -- Found fizz: /data/users/juwin/scratch/homeZjuwinZCacheLib/fbcode_builder_getdeps/installed/fizz -- Found Boost: /data/users/juwin/scratch/homeZjuwinZCacheLib/fbcode_builder_getdeps/installed/boost-3q1puqWKBVvE03fZboaAfiTqx8sfrdLPSNiGTo7FTQU/lib/cmake/Boost-1.83.0/BoostConfig.cmake (found version "1.83.0") found components: iostreams system thread filesystem regex context -- Found mvfst: /data/users/juwin/scratch/homeZjuwinZCacheLib/fbcode_builder_getdeps/installed/fizz -- Found FBThrift: /data/users/juwin/scratch/homeZjuwinZCacheLib/fbcode_builder_getdeps/installed/fbthrift -- Found cachelib: /data/users/juwin/scratch/homeZjuwinZCacheLib/fbcode_builder_getdeps/installed/fizz -- Found mvfst: /data/users/juwin/scratch/homeZjuwinZCacheLib/fbcode_builder_getdeps/installed/mvfst -- Found Boost: /data/users/juwin/scratch/homeZjuwinZCacheLib/fbcode_builder_getdeps/installed/boost-3q1puqWKBVvE03fZboaAfiTqx8sfrdLPSNiGTo7FTQU/lib/cmake/Boost-1.83.0/BoostConfig.cmake (found suitable version "1.83.0", minimum required is "1.58") found components: iostreams context filesystem program_options regex system thread -- Found proxygen: /data/users/juwin/scratch/homeZjuwinZCacheLib/fbcode_builder_getdeps/installed/c-ares-fJOoWaHm8mhW5_cCWvKAjAePYXt5UOAFYGwbgpiezTA -- looking numa in dir: : /usr/include -- root: : -- root: : -- looking numa in dir again : /usr/include -- cachelib include dirs: /data/users/juwin/scratch/homeZjuwinZCacheLib/fbcode_builder_getdeps/installed/cachelib/include/cachelib -- Configuring done (0.2s) -- Generating done (0.0s) -- Build files have been written to: /home/juwin/CacheLib/examples/proxygen_cache/build [ 50%] Building CXX object CMakeFiles/proxygen_cache.dir/main.cpp.o [100%] Linking CXX executable proxygen_cache [100%] Built target proxygen_cache [juwin@devvm29225.atn0 ~/CacheLib/examples/proxygen_cache (pr)]$ ./build/proxygen_cache I20251008 19:51:43.835841 3488174 main.cpp:198] creating cache with size 1069547520 bytes I20251008 19:51:43.836023 3488174 main.cpp:239] Listening on port 8111 ``` Reviewed By: SamirFarhat17 Differential Revision: D84167914 Pulled By: juwinviray fbshipit-source-id: 068a7d0d1d3dcb1ca7446a736c79f59a5c0e7fa0
1 parent 3f6f7ee commit 72f27b5

7 files changed

Lines changed: 722 additions & 1 deletion

File tree

build/fbcode_builder/manifests/libiberty

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ name = libiberty
55
binutils-devel
66
binutils
77

8-
[debs]
8+
[debs.not(all(distro=ubuntu,distro_vers="24.04"))]
99
binutils-dev
1010

11+
[debs.all(distro=ubuntu,distro_vers="24.04")]
12+
binutils-x86-64-linux-gnu
13+
1114
[download]
1215
url = https://ftp.gnu.org/gnu/binutils/binutils-2.43.tar.xz
1316
sha256 = b53606f443ac8f01d1d5fc9c39497f2af322d99e14cea5c0b4b124d630379365
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
cmake_minimum_required (VERSION 3.12)
16+
17+
project(proxygen_cache VERSION 0.1)
18+
19+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
20+
21+
find_package(cachelib CONFIG REQUIRED)
22+
23+
24+
find_package(proxygen CONFIG REQUIRED)
25+
find_package(GTest CONFIG REQUIRED) # GTest::gtest, GTest::gmock
26+
find_package(NUMA REQUIRED) # NUMA::NUMA
27+
find_package(glog REQUIRED) # Glog::glog
28+
29+
add_executable(proxygen_cache main.cpp)
30+
31+
if (TARGET cachelib)
32+
get_target_property(_cachelib_inc cachelib INTERFACE_INCLUDE_DIRECTORIES)
33+
# If it ends in /include/cachelib, step up one level
34+
foreach(dir IN LISTS _cachelib_inc)
35+
if(dir MATCHES ".*/include/cachelib$")
36+
get_filename_component(PARENT_DIR "${dir}" DIRECTORY)
37+
target_include_directories(proxygen_cache PRIVATE "${PARENT_DIR}")
38+
else()
39+
target_include_directories(proxygen_cache PRIVATE "${dir}")
40+
endif()
41+
endforeach()
42+
endif()
43+
44+
target_link_libraries(proxygen_cache PUBLIC
45+
cachelib
46+
GTest::gmock
47+
glog::glog
48+
NUMA::NUMA
49+
proxygen::proxygen
50+
proxygen::proxygenhttpserver
51+
)
52+
53+
get_target_property(_inc cachelib INTERFACE_INCLUDE_DIRECTORIES)
54+
message(STATUS "cachelib include dirs: ${_inc}")

examples/proxygen_cache/build.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/sh
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -e
17+
18+
# default from getdeps.py build cachelib
19+
CLBASE="/data/users/${USER}/scratch/homeZ${USER}ZCacheLib/fbcode_builder_getdeps/installed"
20+
21+
# Additional "FindXXX.cmake" files are here (e.g. FindSodium.cmake)
22+
#CLCMAKE="$CLBASE/cachelib/cmake"
23+
24+
# After ensuring we are in the correct directory, set the installation prefix"
25+
PREFIX="$CLBASE/cachelib/usr/local"
26+
PREFIXB="$CLBASE/"
27+
CMAKE_PREFIX_PATH="$PREFIX/lib/cmake:$PREFIX/lib64/cmake:$PREFIX/lib:$PREFIX/lib64:$PREFIX:$PREFIXB:${CMAKE_PREFIX_PATH:-}"
28+
export CMAKE_PREFIX_PATH
29+
PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig:$PREFIX/lib64/pkgconfig:${PKG_CONFIG_PATH:-}"
30+
export PKG_CONFIG_PATH
31+
LD_LIBRARY_PATH="$PREFIX/lib:$PREFIX/lib64:${LD_LIBRARY_PATH:-}"
32+
export LD_LIBRARY_PATH
33+
34+
mkdir -p build
35+
cd build
36+
cmake $CMAKE_PARAMS ..
37+
make
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# - Find NUMA
16+
# Find the NUMA library and includes
17+
#
18+
# NUMA_INCLUDE_DIRS - where to find numa.h, etc.
19+
# NUMA_LIBRARIES - List of libraries when using NUMA.
20+
# NUMA_FOUND - True if NUMA found.
21+
22+
message(STATUS "looking numa in dir: : ${NUMA_INCLUDE_DIRS}")
23+
message(STATUS "root: : ${NUMA_ROOT_DIR}")
24+
25+
find_path(NUMA_INCLUDE_DIRS
26+
NAMES numa.h numaif.h
27+
HINTS ${NUMA_ROOT_DIR}/include)
28+
29+
message(STATUS "root: : ${NUMA_ROOT_DIR}")
30+
31+
message(STATUS "looking numa in dir again : ${NUMA_INCLUDE_DIRS}")
32+
33+
find_library(NUMA_LIBRARIES
34+
NAMES numa
35+
HINTS ${NUMA_ROOT_DIR}/lib)
36+
37+
include(FindPackageHandleStandardArgs)
38+
find_package_handle_standard_args(NUMA DEFAULT_MSG NUMA_LIBRARIES NUMA_INCLUDE_DIRS)
39+
40+
mark_as_advanced(
41+
NUMA_LIBRARIES
42+
NUMA_INCLUDE_DIRS)
43+
44+
if(NUMA_FOUND AND NOT (TARGET NUMA::NUMA))
45+
add_library (NUMA::NUMA UNKNOWN IMPORTED)
46+
set_target_properties(NUMA::NUMA
47+
PROPERTIES
48+
IMPORTED_LOCATION ${NUMA_LIBRARIES}
49+
INTERFACE_INCLUDE_DIRECTORIES ${NUMA_INCLUDE_DIRS})
50+
endif()

0 commit comments

Comments
 (0)