diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 2ecfe39..1f65619 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -6,6 +6,7 @@ on: - master paths: - 'docs/**' + - 'bench/**' - '.github/workflows/docs.yml' - 'README.md' - 'README.en.md' @@ -27,6 +28,17 @@ jobs: mv ./cppnet/README.md Home.md mv ./cppnet/README.en.md . cd .. + + - name: Run Benchtest + run: | + cd ./bench + ./init.sh + ./build.sh + python3 ./plot.py + mkdir -p ../book/img + mv ./result.png ../book/img/ + cd .. + - name: Upload artifact uses: actions/upload-pages-artifact@v3 with: diff --git a/.gitignore b/.gitignore index 7b42b56..243df4a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ bin build pack compile_commands.json +metrics* +*.png .cache test_bin .clangd diff --git a/README.en.md b/README.en.md index a7de6fc..eb3e26d 100644 --- a/README.en.md +++ b/README.en.md @@ -275,18 +275,38 @@ int main() { - build.sh generates the lib static library and the unit test binary file - docs is the interface documentation - demo is the reference example + - bench is the benchmark ```tree . ├── LICENSE +├── README.en.md ├── README.md +├── bench +│   ├── build.sh +│   └── init.sh +├── demo +│   ├── asset +│   ├── build.sh +│   ├── mnist +│   ├── pack +│   ├── simple-http-server +│   ├── use-lib-server +│   ├── use-lib-server-ssl +│   ├── util +│   └── web-server +├── docs +│   ├── cppnet +│   └── update.sh └── src - ├── build.sh ├── CMakeLists.txt + ├── build.sh ├── cppnet ├── lib ├── release.sh ├── test - └── third_party + ├── third_party + └── win_release.sh + ``` - The source code is mainly placed in `src/cppnet`. ```txt @@ -372,4 +392,3 @@ cppnet ``` ### Class Diagram ![](http://cdn.androidftp.top/test/2024111122224337cppnet.drawio.png) -## TODO diff --git a/README.md b/README.md index 6ca4271..8d2342c 100644 --- a/README.md +++ b/README.md @@ -277,18 +277,38 @@ int main() { - build.sh 生成 lib 静态库以及 单元测试的二进制文件 - docs 是接口文档 - demo 是参考的事例 + - bench 是性能测试 ```tree . ├── LICENSE +├── README.en.md ├── README.md +├── bench +│   ├── build.sh +│   └── init.sh +├── demo +│   ├── asset +│   ├── build.sh +│   ├── mnist +│   ├── pack +│   ├── simple-http-server +│   ├── use-lib-server +│   ├── use-lib-server-ssl +│   ├── util +│   └── web-server +├── docs +│   ├── cppnet +│   └── update.sh └── src - ├── build.sh ├── CMakeLists.txt + ├── build.sh ├── cppnet ├── lib ├── release.sh ├── test - └── third_party + ├── third_party + └── win_release.sh + ``` - 源码主要放置在 `src/cppnet` ```txt @@ -393,5 +413,5 @@ cppnet - [x] 支持SSL - [x] accept 改造 - [x] 完善多线程 -- [ ] 添加压力测试 +- [x] 添加压力测试 - [ ] 提升trie diff --git a/demo/web-server/index.html b/demo/asset/index.html similarity index 100% rename from demo/web-server/index.html rename to demo/asset/index.html diff --git a/demo/asset/init.sh b/demo/asset/init.sh new file mode 100755 index 0000000..985ee27 --- /dev/null +++ b/demo/asset/init.sh @@ -0,0 +1,2 @@ +#!/bin/bash +git clone --depth=1 https://github.com/wuhobin/blog-home diff --git a/demo/simple-http-server/CMakeLists.txt b/demo/simple-http-server/CMakeLists.txt index 8be8227..e5a807f 100644 --- a/demo/simple-http-server/CMakeLists.txt +++ b/demo/simple-http-server/CMakeLists.txt @@ -8,6 +8,18 @@ set(CMAKE_CXX_STANDARD 17) set(ENABLE_SSL ON) add_definitions(-DCPPNET_OPENSSL) +if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + set(OPENSSL_VERSION "") + execute_process( + COMMAND brew list --versions openssl + OUTPUT_VARIABLE OPENSSL_VERSION_OUTPUT + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" OPENSSL_VERSION "${OPENSSL_VERSION_OUTPUT}") + + include_directories(/opt/homebrew/Cellar/openssl@3/${OPENSSL_VERSION}/include) + link_directories(/opt/homebrew/Cellar/openssl@3/${OPENSSL_VERSION}/lib) +endif() # link_libraries(-lssl -lcrypto) add_subdirectory(../../src/lib cppnet) diff --git a/demo/simple-http-server/main.cpp b/demo/simple-http-server/main.cpp index bd4c8b2..f0a9ac9 100644 --- a/demo/simple-http-server/main.cpp +++ b/demo/simple-http-server/main.cpp @@ -30,8 +30,8 @@ int main() { ctx.resp().Redirect("https://chenxuanweb.top"); }); - server.StaticDir("/", "./blog-home"); - server.StaticFile("/", "./blog-home/index.html"); + server.StaticFile("/", "../asset/index.html"); + server.StaticDir("/", "../asset/blog-home/"); rc = server.Run(); if (rc != 0) { diff --git a/demo/web-server/config.json b/demo/web-server/config.json index 8fd29cd..7b0eacc 100644 --- a/demo/web-server/config.json +++ b/demo/web-server/config.json @@ -1,5 +1,5 @@ { - "port":5200, + "port":8080, "host":"127.0.0.1", "is_background":false, "is_guard":false, @@ -13,19 +13,19 @@ "statics":[ { "route":"/", - "path":"./index.html" + "path":"../asset/index.html" }, { "route":"/home", - "path":"./blog-home/index.html" + "path":"../asset/blog-home/index.html" }, { "route":"/", - "path":"./blog-home" + "path":"../asset/blog-home" } ], "ssl":{ - "cert_path":"./ssl/cert_demo.pem", - "key_path":"./ssl/cert_key.pem" + "cert_path":"./ssl/cacert.pem", + "key_path":"./ssl/privkey.pem" } } diff --git a/demo/web-server/init.sh b/demo/web-server/init.sh index 1ac08ad..352b81f 100755 --- a/demo/web-server/init.sh +++ b/demo/web-server/init.sh @@ -1,2 +1,10 @@ #!/bin/bash git clone https://gitee.com/chenxuan520/cppjson + +# if not exist ssl dir +if [ ! -d "./ssl" ]; then + mkdir ssl + cd ssl + # openssl req -x509 -newkey rsa:4096 -sha256 -nodes -keyout privkey.pem -out cacert.pem -days 3650 + openssl req -x509 -newkey rsa:4096 -sha256 -nodes -keyout privkey.pem -out cacert.pem -days 3650 -subj '/C=US/ST=YourState/L=YourCity/O=YourOrganization/OU=YourUnit/CN=example.com' +fi