28
LevelDB ohyecloudy homepage : http://ohyecloudy.com twitter : @ohyecloudy 아꿈사 : http://cafe.naver.com/architect1.cafe 2011.08.06 by

LevelDB 간단한 소개

  • Upload
    -

  • View
    6.200

  • Download
    3

Embed Size (px)

Citation preview

Page 1: LevelDB 간단한 소개

LevelDB ohyecloudy homepage : http://ohyecloudy.com

twitter : @ohyecloudy

아꿈사 : http://cafe.naver.com/architect1.cafe

2011.08.06

by

Page 2: LevelDB 간단한 소개

아~ 이런 게 있구나 본 발표 목적

좀 더 쉽게 얘기하자면 ‘깊이가 없다’입니다.

Page 3: LevelDB 간단한 소개

따끈~ 따끈~ 따끈~ 따끈~ 따끈~ 따끈~ 따끈~ 따끈~ 따끈~ 따끈~ 따끈~ 따끈~ 따끈~ 따끈~ 따끈~

2011.7.27 구글 오픈소스 블로그에 공식적으로 소개

Page 4: LevelDB 간단한 소개

a fast and lightweight key/value DB library

LevelDB는

입니다.

Page 5: LevelDB 간단한 소개

a fast and lightweight key/value DB library

LevelDB는

입니다.

NoSQL

Page 6: LevelDB 간단한 소개

a fast and lightweight key/value DB library

LevelDB는

입니다.

Embedded DB e.g. SQLite

Page 7: LevelDB 간단한 소개

a fast and lightweight key/value DB library

LevelDB는

입니다.

NoSQL Embedded DB

Page 8: LevelDB 간단한 소개

왜 만들었을까? 뭐땀시

Page 9: LevelDB 간단한 소개

웹 애플리케이션용 DB 때문에

웹 애플리케이션이 저장될 캐시를 결정. 지금은 브라우저(크롬, FF, IE…)가 알아서 저장. 오프라인 대비가 잘돼서 모바일에 좋다.

Page 10: LevelDB 간단한 소개

Web SQL Database는 탈락 SQL은 웹 개발과 맞지 않다. ISO 표준이 존재하지만 벤더마다 다양한 SQL문을 지원

Page 11: LevelDB 간단한 소개

IndexedDB 가 유력 B-tree 기반 key/value 저장소 key/value면 웹 애플리케이션이 사용하기에 충분

Page 12: LevelDB 간단한 소개

LevelDB로 IndexedDB를 구현하려고

Page 13: LevelDB 간단한 소개

LevelDB 특징 보기

맛만 살짝~

Page 14: LevelDB 간단한 소개

• Keys and values are arbitrary byte arrays. • Data is stored sorted by key. • The basic operations are Put(key,value),

Get(key), Delete(key). • Multiple changes can be made in one atomic

batch. • Users can create a transient snapshot to get

a consistent view of data. • Forward and backward iteration is supported

over the data. • Data is automatically compressed using the

Snappy compression library.

Page 15: LevelDB 간단한 소개

• Keys and values are arbitrary byte arrays. • Data is stored sorted by key. • The basic operations are Put(key,value),

Get(key), Delete(key). • Multiple changes can be made in one atomic

batch. • Users can create a transient snapshot to get

a consistent view of data. • Forward and backward iteration is supported

over the data. • Data is automatically compressed using the

Snappy compression library.

Page 16: LevelDB 간단한 소개

std::string value; leveldb::Status s = db->Get( leveldb::ReadOptions(), key1, &value); s = db->Put( leveldb::WriteOptions(), key2, value); s = db->Delete( leveldb::WriteOptions(), key1);

Page 17: LevelDB 간단한 소개

• Keys and values are arbitrary byte arrays. • Data is stored sorted by key. • The basic operations are Put(key,value),

Get(key), Delete(key). • Multiple changes can be made in one atomic

batch. • Users can create a transient snapshot to get

a consistent view of data. • Forward and backward iteration is supported

over the data. • Data is automatically compressed using the

Snappy compression library.

simple key/value store와 다른 특징. a persistent ordered map custom comparison function 지원. range query가 싸겠다. 이런 특징 때문에 iteration이 가능

Page 18: LevelDB 간단한 소개

// DB에 있는 모든 key/value 순회

leveldb::Iterator* it =

db->NewIterator(leveldb::ReadOptions());

for (it->SeekToFirst();

it->Valid(); it->Next())

{

cout << it->key().ToString() << ": “ <<

it->value().ToString() << endl;

}

Page 19: LevelDB 간단한 소개

• Keys and values are arbitrary byte arrays. • Data is stored sorted by key. • The basic operations are Put(key,value),

Get(key), Delete(key). • Multiple changes can be made in one atomic

batch. • Users can create a transient snapshot to get

a consistent view of data. • Forward and backward iteration is supported

over the data. • Data is automatically compressed using the

Snappy compression library.

Page 20: LevelDB 간단한 소개

leveldb::ReadOptions options;

options.snapshot = db->GetSnapshot();

//…

// db를 업데이트한다.

leveldb::Iterator* iter = db->NewIterator(options);

// 업데이트를 하기 전 Shapshot DB를 읽는다.

delete iter;

db->ReleaseSnapshot(options.snapshot);

Page 21: LevelDB 간단한 소개

Fast를 붙일 만 해?

Page 22: LevelDB 간단한 소개

전체적으로 뛰어난 성능

Page 23: LevelDB 간단한 소개

다만 value 사이즈가 크면 성능 하락 (value 사이즈가 100,000 byte일 때 성능)

구현상 key와 value를 적어도 두 번 복사하기 때문

Page 24: LevelDB 간단한 소개

정 리

Page 25: LevelDB 간단한 소개

• LevelDB는 NoSQL Embedded DB 이다.

• 웹 애플리케이션용 DB 때문에 만들었다.

– IndexedDB

– 다른 곳에도 더 사용하지 않을까?

• key로 정렬해서 저장한다.

• 전체적으로 뛰어난 성능

– value 사이즈가 크면 성능 저하

Page 27: LevelDB 간단한 소개
Page 28: LevelDB 간단한 소개