Change to set thread number (#153)
author최창규/Tizen Platform Lab(SR)/Engineer/삼성전자 <changyu.choi@samsung.com>
Mon, 15 Mar 2021 07:08:29 +0000 (16:08 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Mon, 15 Mar 2021 07:08:29 +0000 (16:08 +0900)
* Change to set thread number

This patch is set thread number provided at hardware.

Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
* Add to trim memory

Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
* Change trim interval

Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
src/server/runner.cc
src/server/worker_thread.cc

index 604d1f2..6516997 100644 (file)
@@ -33,7 +33,12 @@ namespace pkgmgr_server {
 
 static const std::string SOCK_PATH = "/run/pkgmgr-info-server";
 
-Runner::Runner(int thread_num) : sid_(-1), thread_num_(thread_num) {
+Runner::Runner(int thread_num) : sid_(-1) {
+  if (thread_num > std::thread::hardware_concurrency())
+    thread_num_ = std::thread::hardware_concurrency();
+  else
+    thread_num_ = thread_num;
+
   server_ = std::make_unique<pkgmgr_common::socket::ServerSocket>(SOCK_PATH);
   thread_pool_ = std::make_unique<WorkerThread>(thread_num_);
   sid_ = g_unix_fd_add(server_->GetFd(), G_IO_IN, OnReceiveRequest, this);
index 54c9401..d7f40e1 100644 (file)
@@ -15,6 +15,8 @@
  */
 
 #include "worker_thread.hh"
+#include <sqlite3.h>
+#include <malloc.h>
 
 #include "pkgmgrinfo_debug.h"
 #include "get_appinfo_request_handler.hh"
@@ -136,6 +138,12 @@ void WorkerThread::Run() {
 }
 
 std::shared_ptr<PkgRequest> WorkerThread::PopQueue() {
+  static int cnt = 0;
+  if (++cnt % 50 == 0) { /* trim memory */
+    sqlite3_release_memory(-1);
+    malloc_trim(0);
+  }
+
   auto req = queue_.front();
   queue_.pop();
   return req;