Proper disable pool allocations. + Config oatpp compiler options from cmake.

This commit is contained in:
lganzzzo 2019-03-05 03:09:24 +04:00
parent 6f7b2dcbc1
commit 20c42b95c0
9 changed files with 83 additions and 8 deletions

View File

@ -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)

View File

@ -123,7 +123,7 @@ private:
std::atomic<v_word32> 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<oatpp::concurrency::Thread>[m_threadsCount])
, m_processors(new std::shared_ptr<SubmissionProcessor>[m_threadsCount])

View File

@ -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
/**

View File

@ -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);

View File

@ -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, ...);

View File

@ -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() {

View File

@ -53,7 +53,7 @@ private:
public:
AsyncHttpConnectionHandler(const std::shared_ptr<HttpRouter>& 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<oatpp::async::Executor>(threadCount))
, m_router(router)
, m_errorHandler(handler::DefaultErrorHandler::createShared())
@ -72,7 +72,7 @@ public:
public:
static std::shared_ptr<AsyncHttpConnectionHandler> createShared(const std::shared_ptr<HttpRouter>& 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<AsyncHttpConnectionHandler>(router, threadCount);
}

View File

@ -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);

View File

@ -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);