Speed up your Rails sqlite database for large dataset. This should be a Rails initializer, goes into config/initializers.
if ::ActiveRecord::Base.connection_config[:adapter] == 'sqlite3'
if c = ::ActiveRecord::Base.connection
# see http://www.sqlite.org/pragma.html for details
# Page size of the database. The page size must be a power of two between 512 and 65536 inclusive
c.execute 'PRAGMA main.page_size=4096;'
# Suggested maximum number of database disk pages that SQLite will hold in memory at once per open database file
c.execute 'PRAGMA main.cache_size=10000;'
# Database connection locking-mode. The locking-mode is either NORMAL or EXCLUSIVE
c.execute 'PRAGMA main.locking_mode=EXCLUSIVE;'
# Setting of the "synchronous" flag, "NORMAL" means sync less often but still more than none
c.execute 'PRAGMA main.synchronous=NORMAL;'
# Journal mode for database, WAL=write-ahead log
c.execute 'PRAGMA main.journal_mode=WAL;'
# Storage location for temporary tables, indices, views, triggers
c.execute 'PRAGMA main.temp_store = MEMORY;'
end
end


내가 작성했던 코드.

        int nRetVal = 0;

        nRetVal = m_pDB->execDML(_T("PRAGMA main.page_size = 65536;"));

        nRetVal = m_pDB->execDML(_T("PRAGMA main.cache_size=500000;"));

        nRetVal = m_pDB->execDML(_T("PRAGMA main.synchronous=OFF;"));

        nRetVal = m_pDB->execDML(_T("PRAGMA main.journal_mode=MEMORY;"));

        nRetVal = m_pDB->execDML(_T("PRAGMA main.temp_store = MEMORY;")); 


#include <crtdbg.h>


//기본값을 사용한다. 

_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);  


OUTPUT에 메모리릭이 아래와 같이 출력되었다고 하면..


Detected memory leaks!

Dumping objects ->

{80} normal block at 0x00647380, 796 bytes long.

 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD 

Object dump complete.

The program '[22712] ConsoleApplication2.exe' has exited with code 0 (0x0).



여기서, {80}은 할당인덱스인데, 이 값을 아래 함수에 넘겨, 콜스택을 확인하면 간단하게 메모리 릭 위치를 찾을 수 있겠다.



_CrtSetBreakAlloc(80);



'유지보수 > WinDBG' 카테고리의 다른 글

WINDBG 명령어  (0) 2017.11.16
덤프파일 만들기 관련 글.  (0) 2017.04.26
처리되지 않은 c++ 예외 처리.  (0) 2017.04.21
컴파일 옵션.  (0) 2016.12.08
명령어 정리  (1) 2016.12.07

https://www.liveedu.tv/   

웹기반에 RTMP로 제공하는 라이브.


+ Recent posts