encached: caching server

    The idea of ​​writing a cache server came to me a long time, but there was no suitable reason and tool to start working on it. I wanted to create my cache server for two reasons: experience , the ability to easily add the functions I need (whoever saw the memcached code will understand me). The main problem for me was C ++. Despite the fact that I often come across him, I do not like him at all. I will not start a holivar and write about its shortcomings. I do not like him as much as kefir since childhood: we are incompatible with him. So for me, the big news was the existence of FreePascal . Once upon a time I had experience working on Delphi, so with Pascal I was “on you”. I was especially surprised that FreePascal turned out to be cross-platform (which Delphi did not shine at all).

    What is needed for a cache server? Basically a hash table , network access to it and a means of deleting obsolete records .

    To implement a hash table, I chose a binary tree (maybe not the best way) with chain- based collision resolution . The network interface was implemented using non-blocking sockets.

    To work with the server, I sent a simple text protocol of three commands: GET, PUT, REMOVE.

    Request key data:
    GET\ r \ n
    Answer options:
    • NODATA \ r \ n
    • DATA \ r \ n
    Place data on server:
    PUT\ r \ n
    \ r \ n
    Answer options:
    • SUCCESS \ r \ n
    • HIT \ r \ n (if the transferred data matches the data in the cache)
    • FAILURE \ r \ n
    Delete data:
    REMOVE\ r \ n
    Answer options:
    • SUCCESS \ r \ n
    • FAILURE \ r \ n
    Problems started with the deletion: multi-threaded access to the binary tree can lead to data corruption. Here you need to think and come up with interesting solutions.

    In the hope of an exciting joint development, I posted my developments on github. I really hope that I will find talented programmers among users of Habr. Project address on github: github.com/mdevils/encached

    I would be grateful if you tell me a good way to organize a thread-safe hash table.

    Server Development Plans

    New teams: APPEND, PREPEND, INC, DEC, CAS (Compare and Swap), STAT, TAG (tag entry).
    Full support for multithreaded write / read without locks.
    Control of occupied memory.
    Work under Windows.

    Now the daemon runs on port 2332 under Linux (x86, x86_64), Mac OS X (x86, x86_64). It will probably work under BSD, I have no way to test it.

    The server is built as usual - with the make command. It starts with the argument "-r". The machine must have FreePascal version 2.4.0 installed.

    PS Happy New Year!

    Also popular now: