Localmemcache-0.2.1: The beauty of memcached. For local data. Blazingly fast


#1

Hi,

this release addresses some bugs that people were experiencing and
brings
speed improvements.

===

Localmemcache that aims to provide an interface similar to memcached but
for
accessing local data instead of remote data. It’s based on mmap()'ed
shared memory for maximum speed.

===

Changes for 0.2.1:

  • Fixed a bug that prevented setting values in the hashtable

  • Accessing a closed memory cache does no longer result in a crash

  • Speed improvements: On my machine localmemcache is now only about
    20%
    slower than Ruby’s hash (0.2.0 was about 40% slower)

  • OS X is now officially not supported as it lacks sem_timedwait and
    sem_getvalue (You still can force a build but it won’t be able to
    recover from crashes.)

  • The environment variable LMC_NAMESPACES_ROOT_PATH can now be used to
    override the default, which is /var/tmp/localmemcache

EXAMPLE

require ‘localmemcache’
$lm = LocalMemCache.new :namespace => “viewcounters”
$lm[:foo] = 1
$lm[:foo]
$lm.delete(:foo)

INSTALL

gem install localmemcache

(In case rubyforge has not yet updated the mirrors, fetch the 0.2.1 gem
from here: http://github.com/sck/localmemcache/downloads and then do

gem install localmemcache-0.2.1.gem )

CONTACT

Please contact me with bugs, suggestions and patches at: schween + snafu

de

LINKS

Localmemcache: http://localmemcache.rubyforge.org/
Rubyforge project: http://localmemcache.rubyforge.org/

Source code is hosted on github: http://github.com/sck/localmemcache/

Best,

Sven C. Koehler

4e25d2a677e6723f706d47da4dfd68cd localmemcache-0.2.1.gem
1658b6d660d64dbf57642789f49875e7 localmemcache-0.2.1.tar.gz


#2

El Domingo 05 Abril 2009, Sven C. Koehler
escribió:> Hi,

this release addresses some bugs that people were experiencing and brings
speed improvements.

Hi, I’m trying to install it in my 64 bits Ubuntu host with Ruby1.9.1
installed from sources in /usr/local.

This is the error output I get after doing “gem install localmemcache”:

/usr/local/bin/ruby1.9 extconf.rb install localmemcache
checking for main() in -lrt… *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.

Provided configuration options:
–with-opt-dir
–without-opt-dir
–with-opt-include
–without-opt-include=${opt-dir}/include
–with-opt-lib
–without-opt-lib=${opt-dir}/lib
–with-make-prog
–without-make-prog
–srcdir=.
–curdir
–ruby=/usr/local/bin/ruby1.9
–with-rtlib
–without-rtlib
/usr/local/lib/ruby1.9/1.9.1/mkmf.rb:362:in try_do': The complier failed to generate an executable file. (RuntimeError) You have to install development tools first. from /usr/local/lib/ruby1.9/1.9.1/mkmf.rb:415:intry_link0’
from /usr/local/lib/ruby1.9/1.9.1/mkmf.rb:419:in try_link' from /usr/local/lib/ruby1.9/1.9.1/mkmf.rb:527:intry_func’
from /usr/local/lib/ruby1.9/1.9.1/mkmf.rb:723:in block in have_library' from /usr/local/lib/ruby1.9/1.9.1/mkmf.rb:668:inblock in
checking_for’
from /usr/local/lib/ruby1.9/1.9.1/mkmf.rb:274:in block (2 levels) in postpone' from /usr/local/lib/ruby1.9/1.9.1/mkmf.rb:248:inopen’
from /usr/local/lib/ruby1.9/1.9.1/mkmf.rb:274:in block in postpone' from /usr/local/lib/ruby1.9/1.9.1/mkmf.rb:248:inopen’
from /usr/local/lib/ruby1.9/1.9.1/mkmf.rb:270:in postpone' from /usr/local/lib/ruby1.9/1.9.1/mkmf.rb:667:inchecking_for’
from /usr/local/lib/ruby1.9/1.9.1/mkmf.rb:718:in have_library' from extconf.rb:13:in

mkmf.log is empty. What could I check?
Thanks.


#3

El Domingo 05 Abril 2009, Sven C. Koehler
escribió:> Hi,

this release addresses some bugs that people were experiencing and brings
speed improvements.

Now I’ve installed it in Ruby1.8 with no problem but I think there is
something wrong in the Gem.

Basically if I do:


~# irb1.8
irb> require “localmemcache”
LoadError: no such file to load – localmemcache
from (irb):5:in `require’
from (irb):5

It makes sense since there is no “lib/localmemcache.rb” in the
localmemcache
gem directory.

The only way to load it is by doing:


~# cd /usr/lib/ruby/gems/1.8/gems/localmemcache-0.2.1/src/ruby-binding/
~# irb1.8
irb> require “localmemcache”
true

I understand that, for a normal Gem to work properly, it must create a
“gen_name.rb” in “GEMS_DIR/gen_name/lib/” (this is how all the rest of
Gems
are installed), but localmemcache doesn’t create a “lib” directory.

Regards.


#4

On Sun, Apr 05, 2009 at 09:48:26PM +0200, Iñaki Baz C. wrote:

    from (irb):5

I just checked it with my ubuntu machine and it’s fine for me. Most
likely you didn’t load rubygems properly:

| sck@u:~/$ sudo gem install localmemcache
| Building native extensions. This could take a while…
| Successfully installed localmemcache-0.2.1
| 1 gem installed
| sck@u:~$ irb -rubygems
| irb(main):001:0> require ‘localmemcache’
| => true
| irb(main):003:0> $:
| => ["/var/lib/gems/1.8/gems/localmemcache-0.2.1/bin", “/var/lib/gems/1.8/gems/localmemcache-0.2.1/src/ruby-binding”, “/usr/local/lib/site_ruby/1.8”, “/usr/local/lib/site_ruby/1.8/i486-linux”, “/usr/local/lib/site_ruby/1.8/i386-linux”, “/usr/local/lib/site_ruby”, “/usr/lib/ruby/vendor_ruby/1.8”, “/usr/lib/ruby/vendor_ruby/1.8/i486-linux”, “/usr/lib/ruby/vendor_ruby”, “/usr/lib/ruby/1.8”, “/usr/lib/ruby/1.8/i486-linux”, “/usr/lib/ruby/1.8/i386-linux”, “.”]

-S.


#5

El Lunes 06 Abril 2009, David M.
escribió:> On Sunday 05 April 2009 14:48:28 Iñaki Baz C. wrote:

~# irb1.8
irb> require “localmemcache”

1.9 has gems loaded by default. 1.8 doesn’t. Try:

require ‘rubygems’
require ‘localmemcache’

Sure you are right. Thanks for pointing it out.


#6

El Lunes 06 Abril 2009, Sven C. Koehler
escribió:> I just checked it with my ubuntu machine and it’s fine for me. Most

likely you didn’t load rubygems properly:

Yes, sorry, I forgot to load rubygems in 1.8.

But there is still the issue with Ruby 1.9.1. It’s a different issue.

Thanks.


#7

On Sunday 05 April 2009 14:48:28 Iñaki Baz C. wrote:

~# irb1.8
irb> require “localmemcache”

1.9 has gems loaded by default. 1.8 doesn’t. Try:

require ‘rubygems’
require ‘localmemcache’


#8

On Mon, Apr 06, 2009 at 09:30:12AM +0900, Iñaki Baz C. wrote:

But there is still the issue with Ruby 1.9.1. It’s a different issue.

Ok, I just released localmemcache-0.2.2 which should fix the problems
with Ruby 1.9.

| sck@u:~$ sudo gem install localmemcache
| Building native extensions. This could take a while…
| Successfully installed localmemcache-0.2.2
| 1 gem installed
| sck@u:~$ irb
| irb(main):001:0> require ‘localmemcache’
| => true
| irb(main):002:0> $:
| => ["/var/lib/gems/1.9.0/gems/localmemcache-0.2.2/src/ruby-binding", “/var/lib/gems/1.9.0/gems/localmemcache-0.2.2/bin”, “/usr/local/lib/site_ruby/1.9.0”, “/usr/local/lib/site_ruby/1.9.0/i486-linux”, “/usr/local/lib/site_ruby/1.9/i386-linux”, “/usr/local/lib/site_ruby”, “/usr/lib/ruby/vendor_ruby/1.9.0”, “/usr/lib/ruby/vendor_ruby/1.9.0/i486-linux”, “/usr/lib/ruby/vendor_ruby”, “/usr/lib/ruby/1.9.0”, “/usr/lib/ruby/1.9.0/i486-linux”, “/usr/lib/ruby/1.9/i386-linux”, “.”]

-S.


#9

2009/4/6 Sven C. Koehler removed_email_address@domain.invalid:

On Mon, Apr 06, 2009 at 09:30:12AM +0900, Iñaki Baz C. wrote:

But there is still the issue with Ruby 1.9.1. It’s a different issue.

Ok, I just released localmemcache-0.2.2 which should fix the problems
with Ruby 1.9.

Thanks, it works!

Just a question: Every data I save in localmemcache is converted to
String:

irb> lm[:aaa]=true
true
irb> lm[:bbb]=123
123
irb> lm[:aaa]
“true”
irb> lm[:bbb]
“123”

About the performance, even if localmemcache is just 20% slower than
Ruby Hash, I wonder which is the real performance taking into account
that all the returned values are String, so instead of:

if @do_action

I must do:

if $lm[:do_action] == “true”

However, really thanks for this great utility. It allows for example
running 4 different processes of a Ruby programm in a quad-core CPU
sharing local memory :slight_smile: