Browse Source

[C++]Update cinatra (#8718)

* Create README.md

* Create benchmark_config.json

* Update README.md

* Create cinatra.dockerfile

* Create CMakeLists.txt

* Create main.cpp

* Update cinatra.dockerfile

* Update CMakeLists.txt

* Update README.md

* Update README.md

* Update cinatra.dockerfile

* Update README.md

* Update cinatra.dockerfile

* fix path error in docker file

This cause start failed

* Update cinatra.dockerfile

* Update cinatra.dockerfile

* minor improve performance

* update cinatra

* update cmmmit id

* update dir

* revert dir

* update config

* update url

* update

* update
qicosmos 1 year ago
parent
commit
c4b21c47a0

+ 2 - 2
frameworks/C++/cinatra/README.md

@@ -1,10 +1,10 @@
 # cinatra Benchmarking Test
 
-cinatra is a high-performance, easy-to-use http framework developed in Modern C++ (C++17) with the goal of making it easy and quick to develop web applications using the C++ programming language, located at https://github.com/qicosmos/cinatra
+cinatra is a high-performance, easy-to-use http framework developed in Modern C++ (C++20) with the goal of making it easy and quick to develop web applications using the C++ programming language, located at https://github.com/qicosmos/cinatra
 
 ## Testing Source Code
 
-* [PLAINTEXT](cinatra_benchmark/main.cpp)
+* [PLAINTEXT](example/benchmark.cpp)
 
 ## Test URLs
 

+ 22 - 20
frameworks/C++/cinatra/benchmark_config.json

@@ -1,23 +1,25 @@
 {
   "framework": "cinatra",
-  "tests": [{
-    "default": {
-      "plaintext_url": "/plaintext",
-      "port": 8090,
-      "approach": "Realistic",
-      "classification": "Fullstack",
-      "database": "None",
-      "framework": "cinatra",
-      "language": "C++",
-      "flavor": "None",
-      "orm": "None",
-      "platform": "None",
-      "webserver": "None",
-      "os": "Linux",
-      "database_os": "Linux",
-      "display_name": "cinatra",
-      "notes": "",
-      "versus": "cinatra"
+  "tests": [
+    {
+      "default": {
+        "plaintext_url": "/plaintext",
+        "port": 8090,
+        "approach": "Realistic",
+        "classification": "Fullstack",
+        "database": "None",
+        "framework": "cinatra",
+        "language": "C++",
+        "flavor": "None",
+        "orm": "None",
+        "platform": "None",
+        "webserver": "None",
+        "os": "Linux",
+        "database_os": "Linux",
+        "display_name": "cinatra",
+        "notes": "",
+        "versus": "cinatra"
+      }
     }
-  }]
-}
+  ]
+}

+ 4 - 15
frameworks/C++/cinatra/cinatra.dockerfile

@@ -1,22 +1,11 @@
-FROM ubuntu:18.04
+FROM ubuntu:22.04
 RUN apt-get update -yqq && \
 apt-get install -yqq cmake git uuid-dev gcc g++ autoconf
-ENV ASIO=/asio
-ENV ASIO_INTERNAL=/asio/asio
 ENV CINATRA=/cinatra
-ENV CINATRA_EXAMPLE=/cinatra/example
-WORKDIR /
-RUN git clone https://github.com/chriskohlhoff/asio.git
-WORKDIR $ASIO
-RUN git checkout 8087252a0c3c2f0baad96ddbd6554db17a846376
-WORKDIR $ASIO_INTERNAL
-RUN ./autogen.sh && ./configure
-RUN make && make install
 WORKDIR /
 RUN git clone https://github.com/qicosmos/cinatra.git
 WORKDIR $CINATRA
-RUN git checkout 5acb35cd72c3f72512c0a55e7dea9e25d7779039
-WORKDIR $CINATRA_EXAMPLE
-RUN mkdir build && cd build && cmake .. && make
+RUN git checkout c9bec308e27174c8b7f0f01c92652509f7b47253
+RUN mkdir build && cd build && cmake .. && make -j
 EXPOSE 8090
-CMD ./build/cinatra_example
+CMD ./build/example/benchmark

+ 3 - 54
frameworks/C++/cinatra/cinatra_benchmark/CMakeLists.txt

@@ -5,61 +5,10 @@ include_directories($ENV{CINATRA_HOME})
 if (MSVC)
 	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++latest")
 else ()
-	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}  -O3 -pthread -msse4.2 -std=c++17")
+	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}  -O3 -pthread -std=c++20")
 endif ()
 
-SET(ENABLE_GZIP OFF)
-SET(ENABLE_SSL OFF)
-SET(ENABLE_CLIENT_SSL OFF)
-SET(ENABLE_ASIO_STANDALONE ON)
+add_executable(cinatra_example main.cpp)
+target_compile_definitions(cinatra_example PRIVATE ASYNC_SIMPLE_HAS_NOT_AIO)
 
-if (ENABLE_SSL)
-	add_definitions(-DCINATRA_ENABLE_SSL)
-	message(STATUS "Use SSL")
-endif()
-
-if(ENABLE_GZIP)
-	add_definitions(-DCINATRA_ENABLE_GZIP)
-endif()
-
-if(ENABLE_CLIENT_SSL)
-	add_definitions(-DCINATRA_ENABLE_CLIENT_SSL)
-endif()
-
-if(ENABLE_ASIO_STANDALONE)
-	add_definitions(-DASIO_STANDALONE)
-else()
-	find_package(Boost 1.60 REQUIRED COMPONENTS system)
-endif()
-
-if (ENABLE_SSL)
-find_package(OpenSSL REQUIRED)
-endif()
-if (ENABLE_CLIENT_SSL)
-	find_package(OpenSSL REQUIRED)
-endif()
-
-if (ENABLE_GZIP)
-	find_package(ZLIB REQUIRED)
-endif()
-
-set(CINATRA_EXAMPLE
-	main.cpp
-	)
-
-add_executable(${project_name} ${CINATRA_EXAMPLE})
-include_directories(${Boost_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIR})
-
-target_link_libraries(${project_name} ${Boost_LIBRARIES} uuid -lstdc++fs)
-if (ENABLE_SSL)
-	target_link_libraries(${project_name} ${OPENSSL_LIBRARIES} pthread -ldl)
-endif()
-
-if (ENABLE_CLIENT_SSL)
-	target_link_libraries(${project_name} ${OPENSSL_LIBRARIES} pthread -ldl)
-endif()
-
-if (ENABLE_GZIP)
-	target_link_libraries(${project_name} ${ZLIB_LIBRARIES})
-endif()
 install(TARGETS ${project_name} DESTINATION include)

+ 9 - 15
frameworks/C++/cinatra/cinatra_benchmark/main.cpp

@@ -1,21 +1,15 @@
-#include <iostream>
 #include <include/cinatra.hpp>
+#include <iostream>
 
 using namespace cinatra;
+using namespace std::chrono_literals;
 
 int main() {
-	http_server server(std::thread::hardware_concurrency());
-	bool r = server.listen("0.0.0.0", "8090");
-	if (!r) {
-		std::cout << "listen failed\n";
-		return -1;
-	}
-
-	server.enable_timeout(false);
-	server.set_http_handler<GET>("/plaintext", [](request& req, response& res) {
-		res.set_status_and_content<status_type::ok,res_content_type::string>("Hello, World!");
-	});
-
-	server.run();
-	return 0;
+  coro_http_server server(std::thread::hardware_concurrency(), 8090);
+  server.set_http_handler<GET>(
+      "/plaintext", [](coro_http_request &req, coro_http_response &resp) {
+        resp.need_date_head(false);
+        resp.set_status_and_content(status_type::ok, "Hello, world!");
+      });
+  server.sync_start();
 }