Browse Source

[C++/just-boost] performance issues and alpine upgrade (#8635)

* just-boost added

* performance issues

* alpine upgrade
Jorge Alexandre Delesderrier da Silva 1 year ago
parent
commit
115d5d8648

+ 2 - 2
frameworks/C++/just-boost/just-boost.dockerfile

@@ -1,14 +1,14 @@
 # docker build --progress=plain --build-arg CXXFLAGS="-Wall" -t just-boost -f just-boost.dockerfile .
 # docker build --progress=plain --build-arg CXXFLAGS="-Wall" -t just-boost -f just-boost.dockerfile .
 # docker run --rm --name just-boost -p 8000:8000 -d just-boost
 # docker run --rm --name just-boost -p 8000:8000 -d just-boost
 # docker container stop just-boost
 # docker container stop just-boost
-FROM alpine:3.18
+FROM alpine:3.19
 
 
 ARG APP=just-boost
 ARG APP=just-boost
 ARG CXXFLAGS=-O3
 ARG CXXFLAGS=-O3
 
 
 ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
 ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
 ENV BCPP_PG_CONN_STR="postgres://benchmarkdbuser:benchmarkdbpass@tfb-database/hello_world"
 ENV BCPP_PG_CONN_STR="postgres://benchmarkdbuser:benchmarkdbpass@tfb-database/hello_world"
-ENV BCPP_N_THREADS=32
+#ENV BCPP_N_THREADS=0 # default 0 : number of cores
 
 
 WORKDIR /usr/src/${APP}
 WORKDIR /usr/src/${APP}
 
 

+ 13 - 8
frameworks/C++/just-boost/main.cpp

@@ -117,8 +117,6 @@ handle_target(
 	http::request<Body, http::basic_fields<Allocator>>&& req,
 	http::request<Body, http::basic_fields<Allocator>>&& req,
 	PGconn* conn = nullptr)
 	PGconn* conn = nullptr)
 {
 {
-	static std::string msg = "Hello, World!";
-
 	//std::cout << "handle_target: " << req.target() << std::endl;
 	//std::cout << "handle_target: " << req.target() << std::endl;
 	http::response<http::string_body> res{http::status::ok, req.version()};
 	http::response<http::string_body> res{http::status::ok, req.version()};
 	res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
 	res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
@@ -130,13 +128,13 @@ handle_target(
 	{
 	{
 		// {"message":"Hello, World!"}
 		// {"message":"Hello, World!"}
 		json::object obj;
 		json::object obj;
-		obj["message"] = msg;
+		obj["message"] = "Hello, World!";
 		res.body() = json::serialize(obj);
 		res.body() = json::serialize(obj);
 	}
 	}
 	else if (req.target() == "/plaintext")
 	else if (req.target() == "/plaintext")
 	{
 	{
 		res.set(http::field::content_type, "text/plain");
 		res.set(http::field::content_type, "text/plain");
-		res.body() = msg;
+		res.body() = "Hello, World!";
 	}
 	}
 	else if (req.target() == "/db" || req.target().starts_with("/queries/"))
 	else if (req.target() == "/db" || req.target().starts_with("/queries/"))
 	{
 	{
@@ -328,9 +326,10 @@ do_listen(tcp::endpoint endpoint)
 						{
 						{
 							std::rethrow_exception(e);
 							std::rethrow_exception(e);
 						}
 						}
-						catch (std::exception &e) {
-							std::cerr << "Error in session: " << e.what() << "\n";
-						}
+						catch (std::exception&){}
+//						catch (std::exception &e) {
+//							std::cerr << "Error in session: " << e.what() << "\n";
+//						}
 				});
 				});
 
 
 }
 }
@@ -339,7 +338,13 @@ int main(int argc, char* argv[])
 {
 {
 	auto const address = net::ip::make_address(becpp::env("BCPP_ADDRESS", "0.0.0.0"));
 	auto const address = net::ip::make_address(becpp::env("BCPP_ADDRESS", "0.0.0.0"));
 	auto const port = static_cast<unsigned short>(std::atoi(becpp::env("BCPP_PORT", "8000")));
 	auto const port = static_cast<unsigned short>(std::atoi(becpp::env("BCPP_PORT", "8000")));
-	auto const threads = std::max<int>(1, std::atoi(becpp::env("BCPP_N_THREADS", "3")));
+	auto env_threads = std::atoi(becpp::env("BCPP_N_THREADS", "0"));
+	if (env_threads == 0)
+	{
+		env_threads = std::thread::hardware_concurrency();
+		std::cout << "Using number of cores: " << env_threads << '\n';
+	}
+	auto const threads = std::max<int>(1, env_threads);
 
 
 	std::cout << "__GNUG__=" << __GNUG__ << '\n';
 	std::cout << "__GNUG__=" << __GNUG__ << '\n';
 	std::cout << "__cplusplus=" << __cplusplus << '\n';
 	std::cout << "__cplusplus=" << __cplusplus << '\n';