Giter Site home page Giter Site logo

jruby-memcache-client's Introduction

This projects provides memcached based stores for JRuby. It is a gem based on Ikai Lan's jruby-memcache-client project hosted at http://github.com/ikai/jruby-memcache-client/tree

This project is a JRuby wrapper of the Java MemCache library by Greg Whalin

http://www.whalin.com/memcached/

In production, the standard Ruby MemCache client can cause a thread to hang. In the Glassfish application server, by default there are 5 Grizzly connectors that handle incoming requests. A site that uses MemCache heavily can quickly cause all Grizzly connectors to block and take down a site. I'm hoping that this work I am doing here will help others adopt JRuby as a production platform for their Ruby on Rails applications.

The Ruby MemCache library was never written with threaded applications in mind. All threads use the same socket, and multithreaded mode basically wraps the IO with a Mutex. The Java library provides several features that are not available in the Ruby MemCache library:

- connection pooling
- socket timeouts. In forks of the Ruby MemCache library this is achieved either with a Mongrel timeout or use of the Ruby Timeout class, which, at least at the writing of this README, will work unpredictably when being used as a failsafe against hanging IO.

As of right now this code only provides a very minimal amount of functionality, but it is enough to use with the Rails cache and cache_fu.

Installation
------------
This is a ruby gem that can be installed from gemcutter.org.

You will first need to install the gemcutter gem and configure your system to use it:

jruby -S gem install gemcutter
jruby -S gem tumble

You will then be able to install the JRuby Memcache Client gem:

jruby -S gem install jruby-memcache-client

Java Requirements
-----------------

The underlying library used for this project was compiled using Java 6. You will not be able to run this gem under Java 5 out of the box. You can however clone http://github.com/gwhalin/Memcached-Java-Client and attempt to build it under Java 5 if you must. (You really should consider upgrading to Java 6 since Oracle no longer supports Java 5.)

Replacing Rail's MemCache Client
--------------------------------

Rails ships with a bundled copy of the MemCache client. This client will prevent you from using this gem instead. Adding the following code into your environment.rb file:

if RUBY_PLATFORM =~ /java/i
  # Based on instructions from http://www.mikeperham.com/2009/03/03/using-memcache-client-16x-in-rails-23/
  # Brain surgery to use our own version of memcache-client without
  # having to modify activesupport directly.
  # Unload any previous instance of the class
  if Object.const_defined? :MemCache
    Object.instance_eval { remove_const :MemCache }
  end
  # Pull in the exact version we want
  gem 'jruby-memcache-client', '1.6.1'

  # Ensure that the memcache-client path is at the front of the loadpath
  $LOAD_PATH.each do |path|
    if path =~ /jruby-memcache-client/
      $LOAD_PATH.delete(path)
      $LOAD_PATH.unshift(path)
    end
  end
  # If Ruby thinks it's already loaded memcache.rb, force
  # a reload otherwise just require.
  if $".find { |file| file =~ /\Amemcache.rb\Z/ }
    load 'memcache.rb'
  else
    require 'memcache'
  end
end

This will remove the original MemCache client and load our version of the MemCache class instead.

Configuration
-------------
The JRuby MemCache client uses the same configuration options as the regular MemCache client. Here is how to build the configuration in your environment.rb file:

memcache_options = {
  :namespace => 'fortaleza:production_live:',
}
memcached_servers = [ ENV['MEMCACHED_LOCATION'] || '0.0.0.0:11211']

# Constant used by libs
CACHE = MemCache.new memcached_servers, memcache_options if RUBY_PLATFORM =~ /java/

Note that this may vary based on your particular configuration method and environment.

jruby-memcache-client's People

Contributors

betarelease avatar brynary avatar fredjean avatar ikai avatar pjfitzgibbons avatar ttilley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

jruby-memcache-client's Issues

memcache java library is not compiled for 1.5 compatibility

Try using with java 1.5, you'll get a class version error. Solution is to download the library source and compile it yourself. Be aware it requires 1.5 or higher. Copy the .jar over to where it belongs and things should work. I'd recommend at least a warning that the compiled version included with this client only works with version X and higher.

memcache store incompatibility ? -- undefined method alive?

log/staging.log_2009-08-30T03-50-46:SEVERE: undefined method `alive?' for "0.0.0.0:11211":String
log/staging.log_2009-08-30T03-50-46-    from /Users/pat/Applications/jruby-1.3.1/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/session/mem_cache_store.rb:19:in `any?'
log/staging.log_2009-08-30T03-50-46-    from /Users/pat/Applications/jruby-1.3.1/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/session/mem_cache_store.rb:19:in `initialize'
log/staging.log_2009-08-30T03-50-46-    from /Users/pat/Applications/jruby-1.3.1/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/middleware_stack.rb:72:in `build'
log/staging.log_2009-08-30T03-50-46-    from /Users/pat/Applications/jruby-1.3.1/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/middleware_stack.rb:116:in `each'
log/staging.log_2009-08-30T03-50-46-    from /Users/pat/Applications/jruby-1.3.1/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/middleware_stack.rb:116:in `inject'

Now i created another memcache store to overcome this issue, but ran into marshal data errors afterwards

log/staging.log:ActionView::TemplateError (marshal data too short) on line #93 of app/views/layouts/v1_4.html.erb:
log/staging.log-90:           <% end %>
log/staging.log-91:         
log/staging.log-92:         
log/staging.log-93: <% unless flash[:message].blank? %> log/staging.log-94:
<%= flash[:message] %>

Tried on a new, empty project with rails 2.3.2 and jruby 1.3.1, your ikai gem 1.5.1 and still a nogo
I had used the environment.rb implementation as suggested in your README:


if RUBY_PLATFORM =~ /java/i
  # Based on instructions from http://www.mikeperham.com/2009/03/03/using-memcache-client-16x-in-rails-23/
  # Brain surgery to use our own version of memcache-client without
  # having to modify activesupport directly.
  # Unload any previous instance of the class
  if Object.const_defined? :MemCache
    Object.instance_eval { remove_const :MemCache }
  end
  # Pull in the exact version we want
  gem 'ikai-jruby-memcache-client', '1.5.1'

  # Ensure that the memcache-client path is at the front of the loadpath
  $LOAD_PATH.each do |path|
    if path =~ /ikai-jruby-memcache-client/
      $LOAD_PATH.delete(path)
      $LOAD_PATH.unshift(path)
    end
  end
  # If Ruby thinks it's already loaded memcache.rb, force
  # a reload otherwise just require.
  if $".find { |file| file =~ /\Amemcache.rb\Z/ }
    load 'memcache.rb'
  else
    require 'memcache'
  end
end

memcache_options = {
        :namespace => 'fortaleza:production_live:',
        }
memcached_servers = [ ENV['MEMCACHED_LOCATION'] || '0.0.0.0:11211']

# Constant used by libs
CACHE = MemCache.new memcached_servers, memcache_options if RUBY_PLATFORM =~ /java/

startup error when port not specified

If you specify a server simply by it's ip without a port (1.2.3.4 and not 1.2.3.4:11211) startups fails like:

com.meetup.memcached.SockIOPool Sat May 01 13:39:04 CEST 2010 - ++++ failed to get SockIO obj for: 1.2.3.4
com.meetup.memcached.SockIOPool Sat May 01 13:39:04 CEST 2010 - 1
java.lang.ArrayIndexOutOfBoundsException: 1
at com.meetup.memcached.SockIOPool$SockIO.(SockIOPool.java:1583)
at com.meetup.memcached.SockIOPool.createSocket(SockIOPool.java:780)
at com.meetup.memcached.SockIOPool.populateBuckets(SockIOPool.java:669)

publish the new gem to rubygems

The gem that is published on rubygems is 1.7.0 version which has the wrong jar dependency(java_memcached_dev). This dependency throws an ugly stack trace for lost connection.

The master has the correct dependencies "lib/java/java_memcached-release_2.5.1.jar". Also the master code does not show this stack trace(which is the expected behaviour). Can someone please push the new gem to rubygems.

Thanks

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.