Code Monkey home page Code Monkey logo

memcached.js's Introduction

______  ___                                        ______        _________  _________________
___   |/  /_____ _______ ___ _____________ ___________  /_ _____ ______  /  ______  /__  ___/
__  /|_/ / _  _ \__  __ `__ \_  ___/_  __ `/_  ___/__  __ \_  _ \_  __  /   ___ _  / _____ \
_  /  / /  /  __/_  / / / / // /__  / /_/ / / /__  _  / / //  __// /_/ /___ / /_/ /  ____/ /
/_/  /_/   \___/ /_/ /_/ /_/ \___/  \__,_/  \___/  /_/ /_/ \___/ \__,_/ _(_)\____/   /____/

Memcached.js

Memcached.js is a port of Memcached to Javascript, running on Node.Js.

Install

  $ git clone git://github.com/dalssoft/memcached.js.git
  $ cd memcached.js
  $ ./bin/memcachedjs

What does it do?

From the original project:

"Free & open source, high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.

Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering."

This version:

  • Non blocking operations: "take near constant time to execute, no matter how much data is in the cache."
    • Well, not completely true: adding and removing items to cache allocate memory dynamically, because it doesn't allocate memory upfront when the server starts. So, it may take sometime allocating memory. We will fix it in the future, but for now, it probably won't hurt you.
    • On the other hand, the cache operates on algorithms with O(1) complexity. No complex timers / triggers. Just a hash and linked list.
    • And of course, it uses the non-blocking event machine provided by Node.js
  • Supported commands on this version: get, set, flush_all, delete, add, replace, stats
  • ASCII and Binary memcached protocol

What it doesn't do (yet)?

  • It is not a client for memcached
  • UDP protocol
  • cas, gets, append, prepend, version, quit, incr and decr commands
  • delete queue
  • stats command with params
  • Pre-allocate memory or pagination
  • Sophisticated cache strategies. All it does right now is the old and good LRU, for all items. No discrimination.
    • However, now it uses the same heuristic that the original project uses to clean expired items when it needs more space.

Project goals (sanity is not a prerequirement)

  1. Reach the same performance as C implementation
  2. Implement the same set of features the original project have
  3. Be a hackable memcached implementation

When Memory Is Reclaimed

Memory for an item is not actively reclaimed. If you store an item and it expires, it sits in the LRU cache at its position until it falls to the end and is reused.

However, if you fetch an expired item, memcached.js will find the item, notice that it's expired, and free its memory. This gives you the common case of normal cache churn reusing its own memory.

Items can also be evicted to make way for new items that need to be stored. But before that, we will try to drop a few expired items at the end of the list.

Current State

Currently, the project is Alpha (version 0.0.4), not tested in production enviroment. However, it was tested using diferent scenarios and condition, with different clients (see /test/from_clients folder and the list below).

I haven't done any serious performance test, just simple ones. Compared with the original memcached written in C, memcached.js performance is between 30% and 50% slower. The situation may worsen as new functionality is added (currently, it's ~ 1000 of javascript LOC against ~ 7500 of C LOC, according to CLOC). At the same time, it can be improved since no optimization has been done yet and I can see many places where it could do better.

Tested on Node.js since version v0.3.6-pre. Last check: Node.js v6.3.0

Clients tested:

C/C++:

Ruby:

Node.js:

Perl:

Using Memcached.js

  $ cd memcached.js
  $ ./bin/memcachedjs --log 1

On the client side:

  $ telnet localhost 11211
  stats

Test:

  $ rspec -fd -c test/from_clients/ruby_spec_test.rb

Implemented commands

          ASCII    Bin
Get         X       X
Set         X       X
Add         X       X
Replace     X       X
Delete      X       X
Increment
Decrement
Quit
Flush       X       X
GetQ
No-op               X
Version             X
GetK
GetKQ               X
Append
Prepend
Stat        X
SetQ
AddQ
ReplaceQ
DeleteQ
IncrementQ
DecrementQ
QuitQ
FlushQ
AppendQ
PrependQ

memcached.js's People

Contributors

dalssoft avatar nuxlli avatar tiagogoncalves89 avatar erkan-yilmaz avatar lpmi-13 avatar

Stargazers

 avatar Marcos avatar Renan Bastos avatar Li Xin avatar ishida avatar Dimas Kotvan avatar yanjixiong avatar Gabriel Pedro avatar Jeff Moore avatar  avatar Thiago Massa avatar Rodrigo Navarro avatar Fabrício Ferrari de Campos avatar Chad Wilkin avatar Serge avatar Nikos M. avatar Deividy Metheler avatar Cem Gencer avatar Pedro Nasser avatar Zaid Humaimidi avatar Victor Teixeira avatar Andrew Johnston avatar Tim Spann avatar GyuYong Jung avatar JustVanBlooM avatar  avatar  avatar  avatar Jotarun avatar Guy Korland avatar Roger Mattos avatar Max Kramnik avatar Yuri Karabatov avatar James Jackson avatar  avatar Maksim Ryzhikov avatar Ivan Zhuravlev avatar Markle avatar Michel Bottan avatar thinkphper avatar  avatar  avatar Odie Miranda avatar Janez Troha avatar Barney Chen avatar Masakazu Ishibashi avatar matthiasg avatar  avatar Peter Nitsch avatar  avatar Chandra Patni avatar fengmk2 avatar Anders Thøgersen avatar Veena Basavaraj avatar  avatar Shen Junru avatar Allen Madsen avatar Ben Nicholas avatar Marcos Hack avatar Tom Holder avatar  avatar Luis Cipriani avatar Arnout Kazemier avatar Romain Huet avatar Brian Lee avatar Roger Leite avatar Régis Gaidot avatar Travis Swicegood avatar Fabio Akita avatar Chee Aun avatar

Watchers

Dimas Kotvan avatar  avatar jamus_se avatar

memcached.js's Issues

Fail on memslap run

Running a simple single threaded memslap yells an error.
For some reason most of the "get" results returns as cached miss while the data is in the cache.

guy@ubuntu:~/workspaces/node-workspace/memcached.js$ memcslap --servers=127.0.0.1:11211 -c 1 -t 1s -x 10
servers : 127.0.0.1:11211
threads count: 1
concurrency: 1
execute number: 10
windows size: 10k
set proportion: set_prop=0.10
get proportion: get_prop=0.90
cmd_get: 9
cmd_set: 1
get_misses: 8 <----- 8 misses out of 9
written_bytes: 1735
read_bytes: 1158
object_bytes: 1088

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.