# SQLite에 1분 내로 10억 Row 추가하기

> Clean Markdown view of GeekNews topic #4640. Use the original source for factual precision when an external source URL is present.

## Metadata

- GeekNews HTML: [https://news.hada.io/topic?id=4640](https://news.hada.io/topic?id=4640)
- GeekNews Markdown: [https://news.hada.io/topic/4640.md](https://news.hada.io/topic/4640.md)
- Type: news
- Author: [xguru](https://news.hada.io/@xguru)
- Published: 2021-07-19T10:29:01+09:00
- Updated: 2021-07-19T10:29:01+09:00
- Original source: [avi.im](https://avi.im/blag/2021/fast-sqlite-inserts/)
- Points: 10
- Comments: 0

## Topic Body

- 큰 사이즈의 테스트DB를 빠르게 생성하기 위해 시도한 노력들을 정리

ㅤ→ 현재 최고 수준은 1억 개에 33초 (MBP 2019기준)

- Python 코드로 루프 : 천만개에 15분

ㅤ→ 배치 인서트 사이즈를 10만으로 조정 : 10분으로 단축

- SQLite 설정 최적화 : journal_mode/synchrounous 끄기, 캐쉬사이즈 조정, exclusive lock

ㅤ→ 루프 버전 1억개 10분, 배치 버전 1억개 8.5분

- PyPy 로 변경 : 배치 버전이 1억개에 2.5분으로 단축 (3.5배)

- Rust 로 작성 : 루프 버전 + SQLite 최적화 1억개에 3분

ㅤ→ Prepared Statement 로 변경하고 50 Row 씩 배치 인서트 하니, 1억개에 34.3초

ㅤ→ 쓰레드 버전으로 변경 : 1개의 Writer 쓰레드, 4개의 데이터 쓰레드. 32.37초

- SQLite DB 저장소를 :memory: 로 변경하니 2초 단축해서 29초

ㅤ→ 1억 row 플러시하는데 2초가 걸리는 듯

- 다음으로 시도해 볼 것들 (1분에 10억개 달성을 위해)

ㅤ→ 프로파일링 해보기

ㅤ→ 멀티프로세스 버전으로 4코어를 활용해보기

ㅤ→ Go 언어로 작성한후 GC 꺼버리고 실행

ㅤ→ 크레이지 아이디어 : SQLite 파일 포맷을 배워서 직접 포맷대로 생성하기

## Comments



_No public comments on this page._
