Code Monkey home page Code Monkey logo

kvservice's Introduction

简易KV存储

使用说明

Skiplist

初始化

skiplist::SkipList<int, std::string> sl(0x7fffffff);

接口

bool search(const K& key, V& value);
bool insert(K key, V value);
bool remove(K key, V& value);
void dump(std::string path);
bool load(std::string path);

KVServer

初始化

baidu::rpc::Server server;
if (kv_service.start() != 0) {
    LOG(FATAL) << "Fail to start kv service";
}
if (server.AddService(&kv_service, baidu::rpc::SERVER_DOESNT_OWN_SERVICE) != 0){
    LOG(FATAL) << "Fail to add kv service";
    return -1;
}
baidu::rpc::ServerOptions options;
if (server.Start(FLAGS_port, &options) != 0) {
    LOG(FATAL) << "Fail to start rpc service";
    return -1;
}
server.RunUntilAskedToQuit();

接口

service KVService {
    rpc get(GetRequest) returns (CommonResponse);
    rpc put(PutRequest) returns (CommonResponse);
    rpc remove(RemoveRequest) returns (CommonResponse);
}

设计思路

实现lock free的skiplist, 允许单线程写, 多线程读. 使用hazard point, 保障在读写并 发的场景下,不会因为读取到过期的数据而引起core.

优势

  • 写是wait free,读是lock free

缺陷

  • 单线程写是一个性能瓶颈
  • 并发读写的场景下,部分删除会延时较大

TODO

  • 使用bloom filter提供查询性能
  • 使用后端进程进行GC,优化删除操作

性能测试

对5000000条记录进行CRUD操作, 其中读为5线程并发

ACTION 总耗时(s) 单条耗时(ns)
PUT 5.1 1015
UPDATE 11.6 2326
GET 10.4 1309
DELETE 9.3 1162

kvservice's People

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.