leveldb 간단한 소개

Post on 12-Jun-2015

6.189 Views

Category:

Technology

3 Downloads

Preview:

Click to see full reader

TRANSCRIPT

LevelDB ohyecloudy homepage : http://ohyecloudy.com

twitter : @ohyecloudy

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

2011.08.06

by

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

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

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

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

a fast and lightweight key/value DB library

LevelDB는

입니다.

a fast and lightweight key/value DB library

LevelDB는

입니다.

NoSQL

a fast and lightweight key/value DB library

LevelDB는

입니다.

Embedded DB e.g. SQLite

a fast and lightweight key/value DB library

LevelDB는

입니다.

NoSQL Embedded DB

왜 만들었을까? 뭐땀시

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

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

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

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

LevelDB로 IndexedDB를 구현하려고

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.

• 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.

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);

• 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이 가능

// 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;

}

• 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.

leveldb::ReadOptions options;

options.snapshot = db->GetSnapshot();

//…

// db를 업데이트한다.

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

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

delete iter;

db->ReleaseSnapshot(options.snapshot);

Fast를 붙일 만 해?

전체적으로 뛰어난 성능

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

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

정 리

• LevelDB는 NoSQL Embedded DB 이다.

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

– IndexedDB

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

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

• 전체적으로 뛰어난 성능

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

top related