diff --git a/CMakeLists.txt b/CMakeLists.txt index 81847c37..d4b02cf1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,52 @@ option(BUILD_SHARED_LIBS "Build shared libraries" OFF) option(OATPP_INSTALL "Create installation target for oat++" ON) option(OATPP_BUILD_TESTS "Create test target for oat++" ON) +################################################################################################### +## COMPILATION CONFIG ############################################################################# +################################################################################################### + +option(OATPP_DISABLE_ENV_OBJECT_COUNTERS "Disable object counting for Release builds for better performance" OFF) +option(OATPP_DISABLE_POOL_ALLOCATIONS "This will make oatpp::base::memory::MemoryPool, method obtain and free call new and delete directly" OFF) + +set(OATPP_THREAD_HARDWARE_CONCURRENCY "AUTO" CACHE STRING "Predefined value for function oatpp::concurrency::Thread::getHardwareConcurrency()") +set(OATPP_THREAD_DISTRIBUTED_MEM_POOL_SHARDS_COUNT "10" CACHE STRING "Number of shards of ThreadDistributedMemoryPool") +set(OATPP_ASYNC_EXECUTOR_THREAD_NUM_DEFAULT "2" CACHE STRING "oatpp::async::Executor default number of threads") + +## Print config ################################################################################## + +message("\n############################################################################") +message("## oatpp module compilation config:\n") + +message("OATPP_DISABLE_ENV_OBJECT_COUNTERS=${OATPP_DISABLE_ENV_OBJECT_COUNTERS}") +message("OATPP_DISABLE_POOL_ALLOCATIONS=${OATPP_DISABLE_POOL_ALLOCATIONS}") +message("OATPP_THREAD_HARDWARE_CONCURRENCY=${OATPP_THREAD_HARDWARE_CONCURRENCY}") +message("OATPP_THREAD_DISTRIBUTED_MEM_POOL_SHARDS_COUNT=${OATPP_THREAD_DISTRIBUTED_MEM_POOL_SHARDS_COUNT}") +message("OATPP_ASYNC_EXECUTOR_THREAD_NUM_DEFAULT=${OATPP_ASYNC_EXECUTOR_THREAD_NUM_DEFAULT}") + +## Set definitions ############################################################################### + +if(OATPP_DISABLE_ENV_OBJECT_COUNTERS) + add_definitions(-DOATPP_DISABLE_ENV_OBJECT_COUNTERS) +endif() + +if(OATPP_DISABLE_POOL_ALLOCATIONS) + add_definitions (-DOATPP_DISABLE_POOL_ALLOCATIONS) +endif() + +set(AUTO_VALUE AUTO) +if(NOT OATPP_THREAD_HARDWARE_CONCURRENCY STREQUAL AUTO_VALUE) + add_definitions (-DOATPP_THREAD_HARDWARE_CONCURRENCY=${OATPP_THREAD_HARDWARE_CONCURRENCY}) +endif() + +add_definitions ( + -DOATPP_THREAD_DISTRIBUTED_MEM_POOL_SHARDS_COUNT=${OATPP_THREAD_DISTRIBUTED_MEM_POOL_SHARDS_COUNT} + -DOATPP_ASYNC_EXECUTOR_THREAD_NUM_DEFAULT=${OATPP_ASYNC_EXECUTOR_THREAD_NUM_DEFAULT} +) + +message("\n############################################################################\n") + +################################################################################################### + message("oatpp version: '${OATPP_THIS_MODULE_VERSION}'") add_subdirectory(src) diff --git a/src/oatpp/core/async/Executor.hpp b/src/oatpp/core/async/Executor.hpp index fc4a81d3..c0e1207a 100644 --- a/src/oatpp/core/async/Executor.hpp +++ b/src/oatpp/core/async/Executor.hpp @@ -123,7 +123,7 @@ private: std::atomic m_balancer; public: - Executor(v_int32 threadsCount) + Executor(v_int32 threadsCount = OATPP_ASYNC_EXECUTOR_THREAD_NUM_DEFAULT) : m_threadsCount(threadsCount) , m_threads(new std::shared_ptr[m_threadsCount]) , m_processors(new std::shared_ptr[m_threadsCount]) diff --git a/src/oatpp/core/base/Config.hpp b/src/oatpp/core/base/Config.hpp index e1223df2..03f2a7c3 100644 --- a/src/oatpp/core/base/Config.hpp +++ b/src/oatpp/core/base/Config.hpp @@ -57,10 +57,10 @@ #endif /** - * AsyncHttpConnectionHandler default number of threads + * oatpp::async::Executor default number of threads */ -#ifndef OATPP_ASYNC_HTTP_CONNECTION_HANDLER_THREAD_NUM_DEFAULT - #define OATPP_ASYNC_HTTP_CONNECTION_HANDLER_THREAD_NUM_DEFAULT 2 +#ifndef OATPP_ASYNC_EXECUTOR_THREAD_NUM_DEFAULT + #define OATPP_ASYNC_EXECUTOR_THREAD_NUM_DEFAULT 2 #endif /** diff --git a/src/oatpp/core/base/Environment.cpp b/src/oatpp/core/base/Environment.cpp index 8773cdc7..64f40c9a 100644 --- a/src/oatpp/core/base/Environment.cpp +++ b/src/oatpp/core/base/Environment.cpp @@ -136,6 +136,25 @@ void Environment::setLogger(Logger* logger){ m_logger = logger; } +void Environment::printCompilationConfig() { + +#ifdef OATPP_DISABLE_ENV_OBJECT_COUNTERS + OATPP_LOGD("oatpp/Config", "OATPP_DISABLE_ENV_OBJECT_COUNTERS"); +#endif + +#ifdef OATPP_DISABLE_POOL_ALLOCATIONS + OATPP_LOGD("oatpp/Config", "OATPP_DISABLE_POOL_ALLOCATIONS"); +#endif + +#ifdef OATPP_THREAD_HARDWARE_CONCURRENCY + OATPP_LOGD("oatpp/Config", "OATPP_THREAD_HARDWARE_CONCURRENCY=%d", OATPP_THREAD_HARDWARE_CONCURRENCY); +#endif + + OATPP_LOGD("oatpp/Config", "OATPP_THREAD_DISTRIBUTED_MEM_POOL_SHARDS_COUNT=%d", OATPP_THREAD_DISTRIBUTED_MEM_POOL_SHARDS_COUNT); + OATPP_LOGD("oatpp/Config", "OATPP_ASYNC_EXECUTOR_THREAD_NUM_DEFAULT=%d\n", OATPP_ASYNC_EXECUTOR_THREAD_NUM_DEFAULT); + +} + void Environment::log(v_int32 priority, const std::string& tag, const std::string& message) { if(m_logger != nullptr) { m_logger->log(priority, tag, message); diff --git a/src/oatpp/core/base/Environment.hpp b/src/oatpp/core/base/Environment.hpp index 04ed267e..981dedb3 100644 --- a/src/oatpp/core/base/Environment.hpp +++ b/src/oatpp/core/base/Environment.hpp @@ -143,6 +143,8 @@ public: static v_counter getThreadLocalObjectsCreated(); static void setLogger(Logger* logger); + + static void printCompilationConfig(); static void log(v_int32 priority, const std::string& tag, const std::string& message); static void logFormatted(v_int32 priority, const std::string& tag, const char* message, ...); diff --git a/src/oatpp/core/base/memory/MemoryPool.cpp b/src/oatpp/core/base/memory/MemoryPool.cpp index db3b1d42..7a84743d 100644 --- a/src/oatpp/core/base/memory/MemoryPool.cpp +++ b/src/oatpp/core/base/memory/MemoryPool.cpp @@ -29,6 +29,9 @@ namespace oatpp { namespace base { namespace memory { void MemoryPool::allocChunk() { +#ifdef OATPP_DISABLE_POOL_ALLOCATIONS + // DO NOTHING +#else v_int32 entryBlockSize = sizeof(EntryHeader) + m_entrySize; v_int32 chunkMemSize = entryBlockSize * m_chunkSize; p_char8 mem = new v_char8[chunkMemSize]; @@ -37,6 +40,7 @@ void MemoryPool::allocChunk() { EntryHeader* entry = new (mem + i * entryBlockSize) EntryHeader(this, m_id, m_rootEntry); m_rootEntry = entry; } +#endif } void* MemoryPool::obtain() { diff --git a/src/oatpp/web/server/AsyncHttpConnectionHandler.hpp b/src/oatpp/web/server/AsyncHttpConnectionHandler.hpp index 1cfa9de7..aa955527 100644 --- a/src/oatpp/web/server/AsyncHttpConnectionHandler.hpp +++ b/src/oatpp/web/server/AsyncHttpConnectionHandler.hpp @@ -53,7 +53,7 @@ private: public: AsyncHttpConnectionHandler(const std::shared_ptr& router, - v_int32 threadCount = OATPP_ASYNC_HTTP_CONNECTION_HANDLER_THREAD_NUM_DEFAULT) + v_int32 threadCount = OATPP_ASYNC_EXECUTOR_THREAD_NUM_DEFAULT) : m_executor(std::make_shared(threadCount)) , m_router(router) , m_errorHandler(handler::DefaultErrorHandler::createShared()) @@ -72,7 +72,7 @@ public: public: static std::shared_ptr createShared(const std::shared_ptr& router, - v_int32 threadCount = OATPP_ASYNC_HTTP_CONNECTION_HANDLER_THREAD_NUM_DEFAULT){ + v_int32 threadCount = OATPP_ASYNC_EXECUTOR_THREAD_NUM_DEFAULT){ return std::make_shared(router, threadCount); } diff --git a/test/oatpp/AllTestsMain.cpp b/test/oatpp/AllTestsMain.cpp index 9f31efc2..eddded9d 100644 --- a/test/oatpp/AllTestsMain.cpp +++ b/test/oatpp/AllTestsMain.cpp @@ -52,6 +52,8 @@ public: void runTests() { + oatpp::base::Environment::printCompilationConfig(); + OATPP_RUN_TEST(oatpp::test::base::RegRuleTest); OATPP_RUN_TEST(oatpp::test::base::CommandLineArgumentsTest); diff --git a/test/oatpp/core/base/memory/MemoryPoolTest.cpp b/test/oatpp/core/base/memory/MemoryPoolTest.cpp index 631e3489..533f7a96 100644 --- a/test/oatpp/core/base/memory/MemoryPoolTest.cpp +++ b/test/oatpp/core/base/memory/MemoryPoolTest.cpp @@ -122,11 +122,13 @@ void testPool(v_int32 objectsNumber, v_int32 garbageNumber, v_int32 chunkSize){ } doGarbageAllocs(pool, garbageNumber); - +#ifndef OATPP_DISABLE_POOL_ALLOCATIONS for(v_int32 i = 0; i < objectsNumber; i++){ OATPP_ASSERT(objects[i]->a == -100); } - +#else + OATPP_LOGV("TEST[base::memory::MemoryPoolTest]", "\033[35mWARNING. 'OATPP_DISABLE_POOL_ALLOCATIONS' flag is ON. Assertions disabled.\033[0m"); +#endif delete [] objects; OATPP_ASSERT(pool.getObjectsCount() == 0);