Coder Social home page Coder Social logo

tempbottle / mqdb Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pawelmarc/mqdb

0.0 3.0 0.0 12.04 MB

V8 + 0MQ + LevelDB i multithreaded server

License: BSD 3-Clause "New" or "Revised" License

Makefile 0.05% C++ 86.23% C 0.09% JavaScript 11.84% Shell 0.09% HTML 0.14% CSS 0.01% Python 1.49% Lua 0.03% Scheme 0.03% Batchfile 0.01%

mqdb's Introduction

#MQDB

This is very early alpha release DO NOT USE THIS!!!!

##What it does?

This is database server based on:

  • 0MQ for communication

  • JavaScript V8 for scripting

  • LevelDB for storage

  • WAH bitmaps for indecies

you simply send JS source code of commands to this server and it does all the magic

##Install

To install you need to install 0MQ first

After this run make in leveldb dir

and after make in main dir

After compilation you will have 2 programs:

  • mqdb -- this is server

  • client -- this is sample client to test speed of server

##Using

You can use any language and platform that support 0MQ

Example using C:

    zmq::message_t request (200);
    
	snprintf ((char *) request.data(), 200 ,
        "for(i=1; i<10; i++){ put('db/test','aaa','dane'+i) }");
	
    socket.send (request);

    //  Get the reply
    zmq::message_t reply;
    socket.recv (&reply);
    std::cout << "Received: " << static_cast<char*>(reply.data()) << std::endl;

As you can see we are simply sending JavaScript code to server using 0MQ message. Server returns whatever our script returns or information about error.

##DB API

All functions take name of the database as first argument. It is path to catalog when leveldb will put data. If database does not exist it will be created. In case of some error exception will be raised. If you want to create database "/a/b/s/some_db" the path "/a/b/s/" must exist.

  • put(db_name, key, val) -- returns 1 if success, throws exception in case of error

  • get(db_name, key) -- returns value, or Null if key does not exist, in case of other errors throws exception

  • del(db_name, key) -- returns 1 if success, throws exception in case of error

###Iterator API

  • it_new(db_name) -- returns handle to iterator object for use in other functions, you do not need to deallocate the objects, they are automatically removed after script is executed

  • it_first(it) -- seeks to first element returns 1 if success, throws exception in case of error

  • it_last(it) -- seeks to last element returns 1 if success, throws exception in case of error

  • it_seek(it, val) -- seeks to element equal or greater then val returns 1 if success, throws exception in case of error

  • it_next(it) -- moves to next element returns 1 if success, throws exception in case of error

  • it_prev(it) -- moves to prev element returns 1 if success, throws exception in case of error

  • it_valid(it) -- returns 0 if iterator is no longer valid

  • it_val(it) -- returns current value as string or throws exception

  • it_key(it) -- returns current key as string or throws exception

  • it_del(it) -- if you like you can remove iterator by hand (do not need to)

This code returns all values in database and removes them all while reading

    var ret = []; 
    var i = 0; 
    var it = it_new('db/testb'); 
    for(it_first(it); it_valid(it); it_next(it)){ 
        ret[i++] = {'key': it_key(it), 'val': it_val(it)}; 
        del('db/testb', it_key(it)) 
    }; 
    JSON.stringify(ret)

This code returns all values with keys between "aaa2" and "aaa4"

    var ret = []; 
    var i = 0; 
    var it = it_new('db/testb'); 
    for(it_seek(it, 'aaa2'); it_valid(it) && it_key(it)<'aaa4'; it_next(it)){ 
        ret[i++] = {'key': it_key(it), 'val': it_val(it)}; 
    }; 
    JSON.stringify(ret)

##Extending

MQDB can be very easily extended using JavaScript on server side

##Performance

It is difficult to compare with other systems, because you can make a lot of get/put on the server using one script. On my laptop (4 cores, 8GB RAM) it runs client and server simultaneously with speed about 1000 scripts / second.

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.