Showing posts with label hibernate-memcached. Show all posts
Showing posts with label hibernate-memcached. Show all posts

Tuesday, September 29, 2009

Spymemcached Optimizations Followup

A couple days ago, Dustin Sallings, the other of the spymemcached Java client for memcached, posted an article on some optimizations done to the library. If you are currently using hibernate-memcached you may want to try out the latest spymemcached RC release.

If you combine the latest spymemcached RC release, with memcached 1.4 and the new binary protocol you should see significant performance increases. As Dustin didn't change anything about the spymemcached API it should be a drop in upgrade for you.

spymemcached Optimizations - Dustin Sallings

hibernate-memcached

Enjoy!

Monday, August 10, 2009

Hibernate-memcached 1.2.1 Released

I released 1.2.1 this morning to fix an NPE that was brought up in the group this morning. The NPE only comes up under an error condition so it really shouldn't be affecting too many people. Either way, it was crappy code and it needed to get fixed.

You can download the 1.2.1 from the site, or just update your maven pom.
http://code.google.com/p/hibernate-memcached/

Enjoy!

Friday, July 17, 2009

Hibernate-memcached 1.2 Released

Earlier this week I released hibernate-memcached 1.2. Hibernate-memcached is a simple library that enables the use of Memcached as a second-level cache in Hibernate.

The 1.2 release updates the Maven dependencies to spymemcached 2.3.1, which includes some bug fixes and reduces the dependencies by one jar (spy.jar is gone). The main purpose of the hibernate-memcached release is to add support for the new binary protocol released with memcached 1.4. Previous versions of memcached only supported the ascii protocol. This has always performed well in it's own right; but the binary protocol reduces CPU compute time and can decrease response time as well.

The hibernate-memcached release also includes a minor tweak to use getMulti in Memcached when DogpilePrevention is enabled. Not a big deal, but someone pointed out an opportunity for it; so I added it.

You can download hibernate-memcached here. Or you can setup your maven project by following these instructions. As always, the source is available via github.

Enjoy!
-Ray Krueger

Sunday, December 07, 2008

Hibernate-memcached 1.1.0 Released!

After a bit of trial and error with the maven release plugin, the latest release of hibernate-memcached is available. This release includes a few new features:
  • Support for the Whalin memcached client
  • New Key strategies: Md5KeyStrategy, Sha1KeyStrategy for reducing the length of keys
  • Better Exception handling during cache failure scenarios

This is the first release after moving the source to github.

I need to do some wiki work to get documentation up for how to enable and configure the Whalin/Danga memcached client. I hope to get to that some time this week.

The new KeyStrategy implementations for Md5 and Sha1 are there to reduce the size of the keys. Raymond He emailed me to point out that the obnoxiously long keys that Hibernate generates take up a lot of memory in memcached. Many records + ~250 char keys = a lot of wasted space. The new Md5 and Sha1 keys strategies simply take the fully qualified key name generated by hibernate-memcached and hash them up to take a lot less space.

The improved exception handling revolves around the addition of a new MemcachedExceptionHandler interface and a default LoggingMemcacheExceptionHandler implementation. Essentially the Spy and Danga memcached clients are wrapped up to eat any exception that comes out of them. There's really no reason for the cache layer to throw exceptions at Hibernate. Errors are logged as Errors, and a null is returned.

Enjoy!

Sunday, October 05, 2008

Hibernate-memcached moved to github

I just completed moving the source for the hibernate-memcached project from subversion at GoogleCode to GitHub. There's a great guide at GitHub about importing a project from subversion. The only notes I'd add is that you pretty much have to do the authors file trick or your history won't accurately show you as the person making the changes. Also, I had to push using "-f".


git svn --authors-file=/home/ray/.authors clone http://hibernate-memcached.googlecode.com/svn/tags/hibernate-memcached-1.0 hibernate-memcached
cd hibernate-memcached
git remote add origin git@github.com:raykrueger/hibernate-memcached.git
git push -f origin master
git tag hibernate-memcached-1.0
git push --tags


I probably could have tagged it initially, but I didn't think of it :P

Wednesday, August 20, 2008

Hibernate-memcached 1.0 released into the wild!

This evening I decided it was time to release hibernate-memcached 1.0. It has all the features I intended for it to have and I haven't seen any problems come up with it at all, so it must be time. Please, spend some time checking it out, even if you don't think you're going to use it right now. I'd really love to get some feedback and see if there is anything folks would like to see it do in a future release.

If you have any questions or comments please drop a line here or even use the hibernate-memcached Google group.

So, what next?

Tuesday, August 19, 2008

Hibernate 3.3 and Hibernate-memcached

I spent some time looking over the new Cache SPI released in Hibernate 3.3.0.GA. Definitely a much more in-depth API compared to the old CacheProvider/Cache interfaces. Following the new interfaces (RegionFactory, Region) you can be much more aware as to your specific responsibilities in the caching system.

I have tested that hibernate-memcached remains compatible with hibernate-3.3.0 and everything looks fine. I am going to hold off on implementing a RegionFactory/Region based implementation for now and do that as a post 1.0 release. It will require some refactoring to the current code base to get it to play nice with both APIs (I'd like to stay compatible with 3.2 for a while).

So, look forward to a hibernate-memcached 1.0 release tonight, or maybe tomorrow.

P.S. Hello China! According to Google analytics, a link from javaeye.com is generating 250+ hits a day to the hibernate-memcached project site right now.

Tuesday, August 05, 2008

Hibernate-memcached in the MySQL faq

I was stumbling through google analytics today and saw that there were some referrals coming from dev.mysql.com. Apparently they added a link to the project in both the 5.0 and 6.0 faqs.
Neat!

http://dev.mysql.com/doc/refman/5.0/en/ha-memcached-faq.html
http://dev.mysql.com/doc/refman/6.0/en/ha-memcached-faq.html

Saturday, July 26, 2008

Hibernate-memcached 1.0-RC1 Released

This morning I've released hibernate-memcached 1.0-RC1. This release contains the new Dogpile prevention feature as well as some minor refactoring. If you're using hibernate-memcached, or are even slightly interested in testing out using memcached in combination with hibernate as a second-level cache, you should check this version out.

If you have questions or problems please visit the hibernate-memcached google group.

Friday, July 11, 2008

Dogpile Prevention for Hibernate-memcached

I posted on the hibernate-memcached project that I was going to release a 1.0-RC1 soon. I will, but first I want to implement one more feature that I think people might like; Dogpile Prevention.

If you're only running 2 or 3 instances of your application this really isn't a problem. If you're running 42 instances there is the risk of a "dogpile". If a frequently used item drops from the cache after it's expiration time comes up you run the risk of many instances of your application working concurrently to restore the cached data. Each instance overwriting the other instances attempt to update the cache until everyone sees the data is no longer missing. Other caching systems attempt to remedy this with locking. That's a really bad thing most of the time for scaling as you'd never want to have all the instances of your application synchronized on what one of them is doing.

To remedy this in hibernate-memcached I will follow the patterns mentioned in the article above. This new feature will go in as a configurable option that is, by default, turned off. I plan to make it configurable per cache-region so enabling it would look like hibernate.memcached..dogpile.prevention=true. There is a slight bit of overhead to this is why it won't be on by default. I may make it configurable at the global level as well with something like hibernate.memcached.dogpile.prevention=true.

Once I get this in and tested I plan to release a 1.0-RC1 version of hibernate-memcached.

Tuesday, June 10, 2008

Hibernate-memcached 0.6 released

I've released version 0.6 of the hibernate-memcached integration. Mainly this was to fix the "nextTimestamp" stuff that hibernate uses for query caching. Apparently that value needs to be "course grained" when using a distributed cache.
hibernate-memcached at Googlecode

Saturday, May 31, 2008

Introducing hibernate-memcached

Some of you may, or may not (care), know I am a huge fan of memcached. Its combination of simplicity, elegance and performance make it fantastic choice for any real caching solution.

I've recently begun work on implementing a bridge for using memcached as a second-level cache for hibernate. The project is hosted at googlecode right now, and the code is currently available in the googlecode hosted subversion repositories. In the future I'll probably move it over to github, but subversion is much more accessible to the public at large still.

Adding hibernate-memcached to your hibernate based application is as simple as adding hibernate-memcached.jar, memcached.jar, and spy.jar to your classpath. This can also be done using Maven.

Enabling the hibernate-memcached cache is simple as adding two properties to your hibernate config.

hibernate.cache.provider_class=com.googlecode.hibernate.memcached.MemcachedCacheProvider
hibernate.memcached.servers=server1:11211 server2:11211

Property #1 tells Hibrnate to use the MemcachedCacheProvider. Property #2 tells the MemcachedClient in use what servers to use for the cache. It really is as simple as that.

There are many other configuration properties available to configure things like the default and per-region cache times, operation timeout, hash algorithm to use, and what key strategy to use.

The hibernate-memcached cache is working great for both individual entity caching and query caching. I currently have a lot of work to do around getting documentation up on the googlecode site. It is ready to play with and easy to setup, if anyone out there has the time to check out; please do! If you run into any questions or problems you can post them on the hibernate-memached google group, or open an issue at googlecode.

Thursday, March 13, 2008

Hibernate and Memcached

As I mentioned at the end of my last post, Cache Everything, I am working on building a library to use memcached from Hibernate as a second level cache. That project is hibernate-memcached and its in it's infancy over at googlecode.

The Hibernate second level cache is used to cache items between session invocations. Hibernate always uses it's session as a first level cache, but if you want to avoid database hits between sessions you need a second level cache. If you want these caches to stay in synch between several instances of your application, you need a distributed second level cache.

Memcached is a fantastically fast distributed cache, so why not use that? Once I build a jar of the hibernate-memcached project you'll be able to include it in your application and tell Hibernate to use it. Telling Hibernate to use it means adding the cache_provider property to your hibernate.cfg.xml, or your Spring LocalSessionFactoryBean if you're using that. The hiberante.cfg.xml looks like this...

<hibernate-configuration>
<session-factory>
<property name="hibernate.cache.provider_class">com.googlecode.hibernate.memcached.MemcachedCacheProvider</property>
<mapping class="com.yadda.yadda.Something"/>
</session-factory>
</hibernate-configuration>


Then, in your mappings you tell Hibernate that you want instances of your persistent objects to be cached, or collections from relation ships to be cached. Once Hibernate knows what you want cached you can watch it pump stuff into memcached, which is good clean geeky fun. Fire up memcahed (on windows or linux) using the -vv command line option to make it run "very verbose". You can see it storing and responding for each operation taken.

You can play with the code straight out of subversion at google code. It will actually work and cache stuff, but it is currently hardcoded to look only at localhost:11211 for a memcached instance. I'll get around to making it configurable. To build the code you'll need Maven2. I highly recommend using Don Brown's no-suck port of maven2 actually.

More to come...