Skip to content

Commit 8ab5ad9

Browse files
committed
muduo
1 parent ba4b3bd commit 8ab5ad9

File tree

2,173 files changed

+592657
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,173 files changed

+592657
-0
lines changed

.gdbinit

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# @ put file in ~/.gdbinit
2+
# @ mv ./gdbinit ~/.gdbinit
3+
# @ brief : skip standard .h when gdb
4+
skip -gfi /usr/include/c++/5/*
5+
skip -gfi /usr/include/c++/*/*/*
6+
skip -gfi /usr/include/c++/*/*
7+
skip -gfi /usr/include/c++/*

.gitignore copy

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Ignore all
2+
*
3+
4+
# Unignore all with extensions
5+
!*.*
6+
7+
# Unignore all dirs
8+
!*/
9+
10+
11+
.DS_Store
12+
*/.DS_Store
13+
14+
*.slo
15+
*.lo
16+
*.o
17+
*.obj
18+
19+
# Precompiled Headers
20+
*.gch
21+
*.pch
22+
23+
# Compiled Dynamic libraries
24+
*.so
25+
*.dylib
26+
*.dll
27+
28+
# Fortran module files
29+
*.mod
30+
*.smod
31+
32+
# Compiled Static libraries
33+
*.lai
34+
*.la
35+
*.a
36+
*.lib
37+
38+
# Executables
39+
*.exe
40+
*.out
41+
*.app
42+
43+
44+
**/cmake-build-debug
45+
**/CMakeCache.txt
46+
**/cmake_install.cmake
47+
**/install_manifest.txt
48+
**/CMakeFiles/
49+
**/CTestTestfile.cmake
50+
**/Makefile
51+
**/*.cbp
52+
**/CMakeScripts
53+
**/compile_commands.json
54+
55+
include/divisible/*
56+
bin/*
57+
lib/*
58+
test/test_runner
59+
60+
## Local
61+
62+
.idea/workspace.xml
63+
64+
*/build/*
65+
build/*
66+
build/release/*
67+
build/release-cpp11/*
68+
build/debug-cpp11/*
69+
build/debug/*
70+
build/run/*
71+
build/logs/&
72+
73+
74+
include/*
75+
lib/*
76+
bin/*
77+
.bash/
78+
bin/bootstrap
79+
bin/lib-bash
80+
81+
.idea
82+
83+
.vscode
84+
85+
# Ignore log
86+
*.txt
87+
*.log
88+
*/logs/*
89+
*/*log*

.travis.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
language: cpp
2+
sudo: required
3+
compiler:
4+
- gcc
5+
- clang
6+
os:
7+
- linux
8+
install:
9+
- sudo apt-get install libboost-dev
10+
- sudo apt-get install libprotobuf-dev protobuf-compiler libprotoc-dev libgoogle-perftools-dev
11+
- sudo apt-get install libboost-test-dev libboost-program-options-dev libboost-system-dev
12+
- sudo apt-get install libc-ares-dev libcurl4-openssl-dev
13+
- sudo apt-get install zlib1g-dev libgd-dev
14+
env:
15+
- BUILD_TYPE=debug
16+
- BUILD_TYPE=release
17+
script:
18+
- ./build.sh

CMakeLists.txt

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
cmake_minimum_required(VERSION 3.2)
2+
3+
project(burger C CXX)
4+
5+
enable_language(ASM)
6+
7+
enable_testing()
8+
9+
if(NOT CMAKE_BUILD_TYPE)
10+
set(CMAKE_BUILD_TYPE "DEBUG")
11+
endif()
12+
13+
# only build examples if this is the main project
14+
if(CMAKE_PROJECT_NAME STREQUAL "burger")
15+
option(BURGER_BUILD_EXAMPLES "Build Burger examples" ON)
16+
endif()
17+
18+
set(CXX_FLAGS
19+
-g
20+
# -DVALGRIND
21+
-DCHECK_PTHREAD_RETURN_VALUE
22+
-D_FILE_OFFSET_BITS=64
23+
-Wall
24+
-Wextra
25+
-Werror
26+
-Wconversion
27+
-Wno-unused-parameter
28+
-Wno-unused-variable
29+
-Wno-unused-result
30+
-Wno-unused-but-set-variable
31+
-Wold-style-cast
32+
-Woverloaded-virtual
33+
-Wpointer-arith
34+
-Wshadow
35+
-Wwrite-strings
36+
-march=native
37+
# -MMD
38+
-std=c++11
39+
-rdynamic
40+
-pthread # check
41+
)
42+
43+
if(CMAKE_BUILD_BITS EQUAL 32)
44+
list(APPEND CXX_FLAGS "-m32")
45+
endif()
46+
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
47+
list(APPEND CXX_FLAGS "-Wno-null-dereference")
48+
list(APPEND CXX_FLAGS "-Wno-sign-conversion")
49+
list(APPEND CXX_FLAGS "-Wno-unused-local-typedef")
50+
list(APPEND CXX_FLAGS "-Wthread-safety")
51+
list(REMOVE_ITEM CXX_FLAGS "-rdynamic")
52+
endif()
53+
string(REPLACE ";" " " CMAKE_CXX_FLAGS "${CXX_FLAGS}")
54+
55+
set(CMAKE_CXX_FLAGS_DEBUG "-O0")
56+
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
57+
# set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
58+
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR})
59+
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
60+
set(CMAKE_INSTALL_PREFIX /usr/local)
61+
62+
63+
# find_package(Curses REQUIRED)
64+
find_package(Boost REQUIRED)
65+
find_package(Protobuf)
66+
find_package(CURL)
67+
find_package(ZLIB)
68+
find_path(CARES_INCLUDE_DIR ares.h)
69+
find_library(CARES_LIBRARY NAMES cares)
70+
find_path(MHD_INCLUDE_DIR microhttpd.h)
71+
find_library(MHD_LIBRARY NAMES microhttpd)
72+
find_library(BOOSTTEST_LIBRARY NAMES boost_unit_test_framework)
73+
find_library(BOOSTPO_LIBRARY NAMES boost_program_options)
74+
find_library(BOOSTSYSTEM_LIBRARY NAMES boost_system)
75+
find_path(TCMALLOC_INCLUDE_DIR gperftools/heap-profiler.h)
76+
find_library(TCMALLOC_LIBRARY NAMES tcmalloc_and_profiler)
77+
find_path(HIREDIS_INCLUDE_DIR hiredis/hiredis.h)
78+
find_library(HIREDIS_LIBRARY NAMES hiredis)
79+
find_path(GD_INCLUDE_DIR gd.h)
80+
find_library(GD_LIBRARY NAMES gd)
81+
find_program(THRIFT_COMPILER thrift)
82+
find_path(THRIFT_INCLUDE_DIR thrift)
83+
find_library(THRIFT_LIBRARY NAMES thrift)
84+
85+
if(CARES_INCLUDE_DIR AND CARES_LIBRARY)
86+
message(STATUS "found cares")
87+
endif()
88+
if(CURL_FOUND)
89+
message(STATUS "found curl")
90+
endif()
91+
if(PROTOBUF_FOUND)
92+
message(STATUS "found protobuf")
93+
endif()
94+
if(TCMALLOC_INCLUDE_DIR AND TCMALLOC_LIBRARY)
95+
message(STATUS "found tcmalloc")
96+
endif()
97+
if(ZLIB_FOUND)
98+
message(STATUS "found zlib")
99+
endif()
100+
if(HIREDIS_INCLUDE_DIR AND HIREDIS_LIBRARY)
101+
message(STATUS "found hiredis")
102+
endif()
103+
if(GD_INCLUDE_DIR AND GD_LIBRARY)
104+
message(STATUS "found gd")
105+
endif()
106+
if(THRIFT_COMPILER AND THRIFT_INCLUDE_DIR AND THRIFT_LIBRARY)
107+
message(STATUS "found thrift")
108+
endif()
109+
110+
include_directories(${Boost_INCLUDE_DIRS})
111+
include_directories(${PROJECT_SOURCE_DIR})
112+
include_directories(
113+
${CMAKE_SOURCE_DIR}/thirdparty # find 3rd lib
114+
)
115+
116+
string(TOUPPER ${CMAKE_BUILD_TYPE} BUILD_TYPE)
117+
message(STATUS "CXX_FLAGS = " ${CMAKE_CXX_FLAGS} " " ${CMAKE_CXX_FLAGS_${BUILD_TYPE}})
118+
119+
add_subdirectory(burger/base)
120+
add_subdirectory(burger/net)
121+
add_subdirectory(config)
122+
# add_subdirectory(burger/db)
123+
124+
if(PROTOBUF_FOUND)
125+
add_subdirectory(burger/rpc)
126+
endif()
127+
128+
add_subdirectory(thirdparty/googletest)
129+
add_subdirectory(thirdparty/spdlog)
130+
131+
if(BURGER_BUILD_EXAMPLES)
132+
# add_subdirectory(contrib)
133+
# add_subdirectory(examples)
134+
# else()
135+
# if(CARES_INCLUDE_DIR AND CARES_LIBRARY)
136+
# add_subdirectory(examples/cdns)
137+
# endif()
138+
endif()
139+
140+
if(BUILD_TYPE STREQUAL "DEBUG")
141+
# set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
142+
add_subdirectory(tests)
143+
endif()
144+
145+
add_subdirectory(examples)
146+
147+
if(BUILD_TYPE STREQUAL "RELEASE")
148+
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
149+
# add_subdirectory(examples)
150+
add_subdirectory(benchmarks)
151+
endif()
152+
153+
154+

benchmarks/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# add_executable(ThreadPool_benchmark ThreadPool/ThreadPool_benchmark.cc)
2+
# target_link_libraries(ThreadPool_benchmark burger_base boost_system boost_thread)
3+
4+
# add_executable(logger_benchmark Logger/logger_benchmark.cc)
5+
# target_link_libraries(logger_benchmark burger_base benchmark boost_log boost_thread boost_system)
6+
7+
# add_executable(spd_test spd_test.cc)
8+
# target_link_libraries(spd_test burger_base benchmark boost_log boost_thread boost_system)
9+
10+
add_executable(pingpong_client Throughput/client.cc)
11+
target_link_libraries(pingpong_client burger_net)
12+
13+
add_executable(pingpong_server Throughput/server.cc)
14+
target_link_libraries(pingpong_server burger_net)
15+
16+
add_executable(pingpong_coServer Throughput/coServer.cc)
17+
target_link_libraries(pingpong_coServer burger_net)
18+
19+
add_executable(RingBuffer_benchmark RingBuffer/RingBuffer_benchmark.cc)
20+
target_link_libraries(RingBuffer_benchmark burger_net benchmark)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import os
2+
import string
3+
import datetime
4+
5+
6+
# server : taskset -c 1 xxx
7+
main = "taskset -c 2 ../../build/release-cpp11/bin/chat_loadtest 127.0.0.1 8888 "
8+
>>>>>>> 5833836270ccdba19939a73318ebb6f994990e29
9+
## valgrind
10+
## --tool=helgrind / --tool=drd
11+
## --tool=memcheck --leak-check=full
12+
# main = "valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all ../../build/chat_loadtest 127.0.0.1 8888 "
13+
14+
# fixme : 这样做实验是有问题
15+
# 暂时未用脚本跑实验
16+
# docker中 为什么establish状态20000, time_wait就变成了8192
17+
18+
# main = "../../build/chat_loadtest 127.0.0.1 8888 "
19+
20+
clientsNum = [10, 100, 1000, 5000, 8000]
21+
iterations = 5
22+
23+
# https://www.cnblogs.com/juandx/p/4962089.html
24+
output = open("result_delta_time_with_preCo.txt", "a")
25+
26+
print("Expriment time: " + datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + "\n\n", file=output)
27+
28+
for clients in clientsNum : # 客户端个数
29+
command = main + str(clients)
30+
average_begin = 0.0
31+
average_delta = 0.0
32+
33+
for i in range(iterations) : # 迭代次数
34+
print(i)
35+
f = os.popen(command)
36+
data = f.readlines()
37+
f.close()
38+
begin_time = 0.0
39+
end_time = 0.0
40+
41+
for line in data:
42+
try:
43+
percentage = int(line[3:6].replace(" ", ""))
44+
except ValueError:
45+
continue
46+
else:
47+
if percentage == 0 :
48+
begin_time = float(line[-9:])
49+
average_begin += begin_time
50+
51+
if percentage == 100 :
52+
end_time = float(line[-9:])
53+
average_delta += end_time - begin_time
54+
55+
average_begin /= iterations
56+
average_delta /= iterations
57+
print("Result of " + str(clients) + " clients (Iteration " + str(iterations) + " times) :", file=output)
58+
print("Average Begin time: " + ("%.6f" % average_begin), file=output)
59+
print("Average Delta time: " + ("%.6f" % average_delta) + "\n", file=output)
60+

0 commit comments

Comments
 (0)