Skip to content

[python] Berkeley DB

dsindex edited this page Nov 19, 2014 · 17 revisions

Experiments, BTREE

  • input file
    • key-value 파일
    • key는 대량의 text에서 추출한 유닉한 어절 bigram, value는 빈도수
    • key로 정렬
    • file size = 15G
    • record count = 593678766 line
  • initial cache size : 512M
  • flag : DB_INIT_MPOOL
  • make bdb
    • 빌드 시간
      • 77m22.047s, write speed = 127892 line / sec
    • 최대 메모리 사용량
      • VIR 721M, RES 548M, SHR 544M
      • 메모리 사용량은 cache size에 의존적임
    • bdb files in env directory
    21G 2014-11-13 18:48 bigram.bdb
    512M 2014-11-13 18:48 __db.003  <- cache size
    29M 2014-11-13 18:48 __db.002
    720K 2014-11-14 16:13 __db.001
    
- search bdb
 - sequential search
   - 입력 파일(15G, 593678766 line)을 가지고 다시 탐색하는데 걸리는 시간
   - 입력 파일이 정렬되어 있으므로, cache hit가 계속되는 상황
   - 115m43.328s, read speed = 85507 line / sec
   - 최대 메모리 사용량
     - VIR 682M, RES 546M, SHR 542M 
     - make db에서와 거의 동일하다고 봐도 된다.
 - random search
   - 입력 파일을 랜덤 샘플링해서 10만건을 추출한 이후, 이것으로 테스트
   - os cache는 미리 지운다.
   ```
     $ sudo sh -c "sync; echo 3 > /proc/sys/vm/drop_caches"
   ```
   - 시간 : 190s, read speed = 526 line / sec
   - 참고로 bsearch를 사용한 탐색 시간은 377 line / sec, bsearch보다 약간 빠른 정도임
- modification of cache size
 - 512M cache size로 빌드된 것을 탐색할때, cache size를 늘려도 최대 메모리 사용량은 동일하다.
 - cache size는 'make db'단계에서 결정되기 때문이다.
 - 'make db'에서 cache size를 변경했을때 속도는 아래와 같다. 
 ```
 1) cache size(1G)
    make db : 70m, write speed = 141352 line / sec
    search db(random) : 236s, read speed = 423 line / sec
 2) cache size(2G) 
    make db : 80m47s, write speed = 122483 line / sec
    search db(random) : 179s, read speed = 558 line / sec 
 3) cache size(default)
    make db : 70m18s, write speed = 140982 line / sec
    search db(random) : 133s, read speed = 751 line / sec 
 ```
- 중간 결론
 - cache size를 크게 잡아도 큰 변화는 없음
 - 오히려, default cache size에서 random search 속도가 가장 빨랐음
 - bigram 데이터를 사용하는 모듈의 입력은 일반적은 문서. 따라서, 자주 등장하는 bigram pattern이 계속해서 발생할 가능성이 높고 사용하면 할수록 cache에 올라가서 속도가 빨라진다. 하지만, random search 속도가 지나치게 느리다. 모듈을 사용하기 전에, 전체 sequential search를 통해 cache에 올리는 작업을 항상 할수도 없는 일이고... 

### Experiments, HASH
- BTREE를 HASH로만 바꿔서 테스트 진행
- initial cache size : default
- flag : DB_INIT_MPOOL
- make db
 - 빌드 시간
   - 4시간 정도에 5억 2천만건 정도를 insert하는데, 그 이후 급격하게 느려진다. 8시간이 지나도 5억 7천만건을 넘지 못한다. 그래서 insert 중지.
 - bdb files in env directory(5억 6천 4백만건 정도까지)
 ```
 39G 2014-11-15 01:05 bigram.bdb
 264K 2014-11-15 01:05 __db.003
 64K 2014-11-15 01:05 __db.002
 720K 2014-11-14 17:46 __db.001
 ...
  • search db(random)
    • 완전하게 빌드되지는 않았지만, 이런 상태에서 테스트해봤다. 간단하게, 속도정도는 알수 있을것 같으니....
    • 시간 : 722s

Reference

Install Berkely DB 6.1.x and python bindings

download 'db-6.1.19.gz' and install

$ pip install bsddb3 

you are linking a Berkeley DB version licensed under AGPL3 or have a commercial license. 
AGPL3 is a strong copyleft license and derivative works must be equivalently licensed. You have two choices: 

 1. If your code is AGPL3 or you have a commercial Berkeley DB license from Oracle, please, define the environment variable 'YES_I_HAVE_THE_RIGHT_TO_USE_THIS_BERKELEY_DB_VERSION' to any value, and try to install this python library again. 

 2. In any other case, you have to link to a previous version of Berkeley DB. Remove Berlekey DB version 6.x and let this python library try to locate an older version of the Berkeley DB library in your system. Alternatively, you can define the environment variable 'BERKELEYDB_DIR', or 'BERKELEYDB_INCDIR' and 'BERKELEYDB_LIBDIR', with the path of the Berkeley DB you want to use and try to install this python library again. 

$ export YES_I_HAVE_THE_RIGHT_TO_USE_THIS_BERKELEY_DB_VERSION=1

Code

Other embedded key-value db

Clone this wiki locally