Archive for the ‘Java’ Category

Debugging Ext JS in IntelliJ 9.0.2 (Maia IU.92.273)

Tuesday, February 16th, 2010

I am working on Ehcache Monitor right now, which uses Ext JS. IntelliJ gives you the ability to debug both Java and JavaScript, which is really nice.

Local Debugging

To debug in IntelliJ you right click on a .html file and select Debug.

Remote Debugging

Set up a JavaScript Debug Remote configuration. See below for an example.

Make sure Firefox is closed and any previous debug session is closed.

Then Debug the Javascript Debug Remote config.

Getting it to Work

We had a bit of pain getting this working.

Mac OS X Version

10.6.2

IntelliJ Versions

I tested 9.0, 9.0.1 but couldn’t get it to work. It is known to work with Maia IU.92.273 which will become 9.0.2. It will install a FireFox plugin called JetBrains Firefox Extension. The version should be 0.2.5. 9 and 9.1 shipped with a 0.1 version of this plugin.

I am using Java 1.6_17.

Firefox Bug

Firefox gives an error mentiowith sqlite3 when using the HTML and JavaScript debugger.

This is caused by a bug in Firefox 3.5.7 and a few versions back. This problem has been reported on SnowLeopard.

Dyld Error Message:
Library not loaded: /usr/lib/libsqlite3.dylib
Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security
Reason: Incompatible library version: Security requires version 9.0.0 or later, but libsqlite3.dylib provides version 1.0.0

Dyld Error Message:  Library not loaded: /usr/lib/libsqlite3.dylib  Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security  Reason: Incompatible library version: Security requires version 9.0.0 or later, but libsqlite3.dylib provides version 1.0.0

This is a known issue in Firefox. See https://bugzilla.mozilla.org/show_bug.cgi?id=513747

The workaround is to change the Browser config to use firefox-bin rather than firefox. See below.


Ehcache welcomes Grails as a first-class supported framework

Wednesday, December 9th, 2009

The Ehcache project is happy to welcome Grails to the fold. The new Grails 1.2RC1 uses Ehcache as the default Hibernate second level cache. We worked with the Grails community to test Ehcache with Grails to ensure a good developer experience. As part of that we have added a new Grails Chapter to the Ehcache documentation on how to configure Ehcache for Grails, including production tuning.

We plan further enhancements to Ehcache to roll in the Terracotta Hibernate provider so that Grails users can experience the Terracotta Scale Continuum by simply making config changes in ehcache.xml.

Note that earlier versions of Grails also ship with the Ehcache library and it very quick and easy to configure it. See the documentation.

New 1.7.1 GA release – ehcache, ehcache-core and ehcache-terracotta

Monday, November 30th, 2009

This is a final GA release of ehcache-1.7.1 comprising ehcache, ehcache-core and ehcache-terracotta modules.

This release contains 15 fixes and improvements over 1.7.0. See the changelog for complete details. Downloads and Maven modules are available here.

Very significantly, this release will enable new GA releases of the other ehcache modules, such as ehcache-web, which we expect to release over the next few weeks.

Note: If you experience different caching ergonomics you can enable the LinkedHashMap based engine with java -Dnet.sf.ehcache.use.classic.lru=true. This is the engine enabled up to 1.5.

It’s Thanksgiving: Here is what we have been cooking up for Ehcache

Friday, November 27th, 2009

I am over in the US through to Christmas and enjoying my second only Thanksgiving here. It has put me in a reflective mood. We have been hard at work on Ehcache over the last few months and I want to give everyone an update on some cool stuff coming out soon.

Ehcache-1.7.1

1.7.1 contains 15 bug fixes and improvements. That is quite a lot for an ehcache release, but reflects some serious time put in by the Terracotta Transparency Engineering Team, together with the impact of the large changes made in 1.7.0 when we integrated with Terracotta.

The biggest thing is that 1.7.1 is ready for some serious business. Start with local caching, and choose from Terracotta open source, RMI, JGroups or JMS for clustering and replication. RMI and JGroups work well up to around 20 nodes, and up to as much data as you can comfortably deal with in your local node, around 5GB in memory and more if you overflow to disk. If you need more than that, or your need coherence, or you need 99.99+ then plugin in Terracotta. This last one costs money, but it is worth it and cheaper and better than the competition. With that solution you can scale as far as you want. Literally. In the new year I plan on showing how to take this to a 1 Terabyte coherent cache with 99.999% availability and class-leading performance.  In the marchitecture, we call this the Scale Continuum, because that is what it is.

The other really big thing is that 1.7.1 completes the modularisation that was started over a year ago. The other ehcache modules will all have new releases, many of these the first non-beta releases as modules, in the next few weeks.

Google App Engine

Back in June I made some tweaks to support Ehcache in Google App Engine. At the time I suggested how this could be used with JCache and Google’s cache infrastructure. Because of GAEs restrictions, it did not include CacheLoaders. In 1.7.1 CacheLoaders have been changed to support GAE. And now, with a contribution from Cedric Lime, the ehcache-googleappengine module has been created. That one is fully integrated. It uses Ehcache as a high performance in-process L1 cache and GAE’s cache infrastructure as an L2. Why is this cool? Ehcache is 3 orders of magnitude faster. This means your apps will be faster, will do far less network calls to the cache infrastructure and will cost you a lot less in data and CPU charges. And you can build your apps as you are used to

Grails becomes a first-class citizen

I am a big fan of Grails, as are my Terracotta colleagues. Ari Zilka, Terracotta CTO,  ran into Graeme Rocher, the maintainer, a few weeks ago at SpringOne, and we thought it was high time  we offer Grails first class support. With that in mind I have been working with Graeme, testing Ehcache 1.5, which is already included in Grails-1.1.1, but is not active by default. It all works great. There will be a new Grails chapter (yes, this is the link, but I have not quite put it up) in the Ehcache documentation on Grails, showing step by step how to get up and running with Ehcache and Grails in about two minutes, with a couple of config line changes. Of course, with ehcache-1.7.1, this means that the Grails is a first-class citizen and can use our technology to scale up to massive apps.

Coming in early 2010: a new unified Hibernate Caching Provider

Ehcache of course started life as the “Easy Hibernate Cache”, thus ehcache and we remain committed to being the very best Hibernate caching provider. Now just prior to Ehcache joining Terracotta, Terracotta released a killer provider. As well as integrating with Terracotta clustering, it uses bytecode manipulation to remove syncrhonization required by caching providers (not Ehcache) and screams. Now that we have two providers, and Ehcache is already integrated with Terracotta via the ehcache-terracotta module, we plan to simplify everyone’s lives and unify the two by making a new ehcache provider which will work with ehcache but also with Terracotta.

OpenJPA becomes a first-class citizen

With JPA 2 about to make it out the door, a lot of folks have been playing with JPA by using Hibernate through it, or by using DataNucleus in GAE (at least I have). Earlier this year Craig Andrews contributed a patch for OpenJPA. That was released a few months back as the ehcache-openjpa module 0.1. In the best open source tradition the idea was to release it and get feedback. Now, we have that feedback, including from OpenJPA lead Kevin Sutter, and we have been readying 0.2. Once again, as with the OpenJPA ehcache provider can take you all the way along the scale continuum. We should have this released in the next week.

Ehcache DX Monitoring and Management

A few months ago I used the MySQL Enterprise Monitor. It turned out to be very useful to debug a gnarly problem we were having. It got me thinking that Ehcache could do with its own monitor for the same reason. Given that it would need to collect data from each CacheManager in your enterprise, and that most operations monitoring tools charge per monitor, an Ehcache Monitor would also provide a cheap and convenient consolidation point for integration with those tools. Now, at Terracotta, we think that caching should be a first-class component of your architecture, and therefore it needs first-class tools.

A few weeks ago we put out our first beta of this product and have been getting feedback. With the first cut working I have been thinking the past few weeks that I need to instil my knowledge of every caching issue I have ever had to investigate, and all the ones I have helped others with, into this tool. In other words, give it the secret sauce. In my opinion this will make the tool invaluable for production Ehcache environments.

Here is a peek at what is getting added into the next cut:

  1. Simplified SLA monitoring, using our HTTP interface
  2. Statistics switchable between instantaneous and cumulative
  3. A week or two’s history, for comparative analysis, and for finding the dreaded issues in your new application release
  4. Graphing of numerous Cache Efficiency statistics
  5. Graphing of Full GC and other GC events. Why? Because this is critical for apps with large heaps, which caching apps have
  6. Graphing of actual and projected memory use for each Cache. Wow! This one will be great.
  7. Clear a cache in all nodes across the whole enterprise with one click.  (This one would have been useful )

Ok, so those are features, but how will that work on the ground. Well, I have been thinking about that and here is just one use case.

A new system is put into production with Ehcache. After 3 months, the users notice that the system is getting slow. Operations sets up SLA-alerts on page response time which immediately fail. They then set up alerts on average get time of 100 ms on any cache in the app’s main cachemanager – which immediately fails. 2nd level support is contacted. The av get time graph for a series of caches are reviewed. com.company.process.domain.Country cache shows a get time of 300ms. The graph history which goes back 2 weeks shows that it jumped a week ago and a week and a half ago. The config on the config tab is checked and it is noted that the max elements in memory is set to 50. The statistics tab shows that there are 50 elements in memory and 2 on disk. The memory consumption tab shows that used cache memory equals max predicted memory for the cache. The 2nd level support checks with apps administrators and discover that the system has been rolled out to more countries and is now at 52, with more coming. Solution: up the maxElementsInMemory to > 52.

To get involved in helping us shape the Monitor, you can download the first cut here. If you do, ping us with your feedback and we will incorporate it in the next cut which we will be starting work on in the next week.

Anyway, as everyone can see, I have been up to a few things since I started working on Ehcache full-time a month ago. Look out for next year!

Monday, November 2nd, 2009

See a 3 minute video of Greg Luck previewing Ehcache DX, the new monitoring and management product, for Ehcache versions 1.2.3 and higher. Help to shape this exciting new product by registering and downloading theEhcache DX early release.

What is d7073c02eca990a65c2c4c911fe33b20?

Tuesday, August 18th, 2009

As many of you have guessed d7073c02eca990a65c2c4c911fe33b20 is an MD5 hash. It is actually a hash of a zip archive of documentation for the acquisition by Terracotta Inc. of Ehcache. Adding an MD5 hash into a contract caused the lawyers some angst. They hadn’t seen it before and were naturally reluctant to include it.

The MD5 went through multiple revisions but the final hash is the one I blogged and tweeted. My new colleagues at Terracotta got in on the fun and also started blogging and twittering. We then watched the fun unfold on the blogosphere and twittersphere as people searched for what is obviously a unique string and looked for the patterns.

The prize goes to Matt Raible for getting closest to the correct answer.

What is Happening

Terracotta Inc. is acquiring Ehcache. On one side we have a late stage startup and on the other an open source project. So what does that mean? It means the copyright notices in Ehcache source code change to Terracotta Inc, I join Terracotta, and we get on it. The status of the many contributors to Ehcache who have licensed their code to the Ehcache project remains unchanged.

Why is it Happening?

The timing of this is perfect for both Ehcache and Terracotta. Reflecting on it with Amit Pandey, CEO and Ari Zilka, CTO of Terracotta Inc, we realised that this would not have happened a year ago and may not have happened a year from now. Ehcache and Terracotta have been cooperating for the last two years since I agreed with them at JavaOne 2007 to do an integration. To me distributed caching was a hard problem and I have invited all comers to solve it. We now have four mechanisms: RMI, JGroups, JMS and Terracotta. The Terracotta integration provides coherence, massive scale and visibility. The integration has been so successul that fully 50% of Terracotta’s customers use Terracotta via Ehcache. This presented both an opportunity and a challenge for Terracotta. Fortunately for the Ehcache community, Terracotta have taken the opportunity to acquire Ehcache.

What about open source

Ehcache is a project committed to open source goals. Bottom up construction with the community driving innovation. As anyone who has submitted a bug report or patch to Ehcache knows, I seriously consider every contribution and incorporate most of them – all with a maniacal attention to detail and quality. Ehcache has always followed the benevolent dictator open source model. Commit access is closely guarded but contributions are welcome.

What stands behind my approach to Ehcache and other open source projects I maintain is my open source philosophy: “Simply and naively, why not make the world a better place?”. It is entirely possible to do well and help others at the same time.

News flash: Terracotta is also an open source company. The difference is they have a business model.

I also think there is a consolidation going on in distributed caching. Ehcache has been on the winning end of that, and now with Terracotta’s help, we will jointly strive to continue that past success.

What this means for Ehcache Users

  1. Ehcache remains under the Apache 2 license
  2. New feature development is accelerated with the addition of a team of engineers working full-time on Ehcache
  3. I am full-time on Ehcache. I have not had the time I would have liked to devote to Ehcache (I have been doing a miserly 10-15 hours per week for the past 6 years) but now I do. Look out!
  4. Ehcache extends its standards support. There are multiple emerging standards in this area and I plan to work with the community to lead further standardisation efforts. A lack of time has been my biggest obstacle in doing more on this to date.
  5. Ehcache gets new hosting at ehcache.org with
    state-of-the-art forums, source control and bug reporting. The changes will happen slowly and carefully.

  6. File release at sourceforge.net is retained
  7. Maven deployment to oss.sonatype.org and Maven Central is retained.
  8. Distributed caching via Terracotta is seamless. Ehcache users can have full confidence that they can start single node and scale as high as they need to with Enterprise features.
  9. Enterprise support, training and professional services for Ehcache. I have provided these for a few years now, but now we will have the full Terracotta organisation behind them with the usual SLAs.

What this means for Terracotta Users

  1. Ehcache APIs will replace Terracotta distributed cache APIs as a single caching interface / standard for Terracotta distributed caching
  2. a single-node version of Terracotta ala Ehcache will be available for the first time
  3. Full freedom to run on the latest version of Ehcache at all times, knowing it will work with Terracotta
  4. Single vendor support structure for caching interfaces / libraries as well as their scalability / reliability runtime.
  5. the investment protection of standards

More

See Terracotta’s news announcement for more detail.

Terracotta founder and CTO Ari Zilka has a blog post on the acquisition. He explains the same material from a Terracotta viewpoint and gives insight into the product roadmap.

At last, the important stuff

The Terracotta – Ehcache blend is a natural one that works. What has really been occupying my attention the last week is deciding pronunciation issues. Anyone who has attended my JavaOne sessions knows that I pronounce Ehcache as “ee h kay sh“. Alternative pronunciations in use are “eh cash” (USA) and “eh kay sh” (Canada and Atlassian). Given that Ehcache is going to be around for a long while and I am the founder let me state that the official pronunciation is “ee h kay sh“. Now let’s get on with it.

? d7073c02eca990a65c2c4c911fe33b20 ?

Friday, August 14th, 2009

Performance problems in ConcurrentHashMap vs synchronized HashMap

Friday, June 26th, 2009

In Ehcache 1.6, HashMap was replaced with ConcurrentHashmap with statistical sampling for eviction.
Having completed 1.6 and released it there were a few surprises along the way with ConcurrentHashMap performance.

PUT and GET performance

There is some existing material online about ConcurrentHashMap versus HashMap performance, notably http://www.informit.com/guides/content.aspx?g=java&seqNum=246.
This article finds that ConcurrentHashMap puts are slower than HashMap when the map gets large: for a map of 1 million objects fully population took three times longer than HashMap for a single threaded scenario. However once you get to multi-threaded scenarios, you need to put synchonrization around HashMap. For those few of you in doubt as to this, email me your HashMap usage I will send you back a multi-threaded test that turns your computer into a fan heater (i.e. 100% infinite loop in the CPUs) in about 30 seconds. The cost of synchronization grows as you add concurrency. Put and Get work well with ConcurrentHashMap in multi-threaded scenarios.

Iterate Performance

iterate in ConcurrentHashMap is a lot slower than it is in HashMap and get worse as the map size gets larger. See CacheTest#testConcurrentReadWriteRemoveLFU. For my testing scenarios, which uses 57 threads doing a majority of gets but doing other operations with a variety of map sizes, we get:

* With iterator:
* 1.6 with 100,000 store size: puts take 45ms. keySet 7ms
* 1.6 with 1000,000 store size: puts take 381ms. keySet 7ms
* 1,000,000 - using FastRandom (j.u.Random was dog slow)
* INFO: Average Get Time for 2065131 observations: 0.013553619 ms
* INFO: Average Put Time for 46404 obervations: 0.1605034 ms
* INFO: Average Remove Time for 20515 obervations: 0.1515964 ms
* INFO: Average Remove All Time for 0 observations: NaN ms
* INFO: Average keySet Time for 198 observations: 0.0 ms
* 9999 - using iterator
* INFO: Average Get Time for 4305030 observations: 0.006000423 ms
* INFO: Average Put Time for 3216 obervations: 0.92008704 ms
* INFO: Average Remove Time for 5294 obervations: 0.048545524 ms
* INFO: Average Remove All Time for 0 observations: NaN ms
* INFO: Average keySet Time for 147342 observations: 0.5606073 ms
* 10001 - using FastRandom
* INFO: Average Get Time for 4815249 observations: 0.005541354 ms
* INFO: Average Put Time for 5186 obervations: 0.49826455 ms
* INFO: Average Remove Time for 129163 obervations: 0.015120429 ms
* INFO: Average Remove All Time for 0 observations: NaN ms
* INFO: Average keySet Time for 177342 observations: 0.500733 ms
* 4999 - using iterator
* INFO: Average Get Time for 4317409 observations: 0.0061599445 ms
* INFO: Average Put Time for 2708 obervations: 1.0768094 ms
* INFO: Average Remove Time for 17664 obervations: 0.11713089 ms
* INFO: Average Remove All Time for 0 observations: NaN ms
* INFO: Average keySet Time for 321180 observations: 0.26723954 ms
* 5001 - using FastRandom
* INFO: Average Get Time for 3203904 observations: 0.0053447294 ms
* INFO: Average Put Time for 152905 obervations: 0.056616854 ms
* INFO: Average Remove Time for 737289 obervations: 0.008854059 ms
* INFO: Average Remove All Time for 0 observations: NaN ms
* INFO: Average keySet Time for 272898 observations: 0.3118601 ms

In summary, with 1 million objects in the map a put to Ehcache using iterate for eviction, takes 381ms!

As a result I have used an alternative to iteration using an algorithm called FastRandom. The result is 0.16 ms, 2,300 times faster!

For very small maps, ConcurrentHashMap iteration is quite quick. From experimental testing in Ehcache 1.6 we use iteration up to 5000 entries and FastRandom for sizes above that.

size() performance

Thought not as bad as iteration I have noted size as slow in ConcurrentHashMap compared to HashMap. In Ehcache 1.6 we limit the the usage of size().

Recommendations

If you using ConcurrentHashMap and using more that get/put, test the performance. It may be far, far worse than you were expecting.

To give ConcurrentHashMap the best chance of optimisation remember to set the size and expected concurrency when you create it. In ehcache we set the size to the exact size configured for the cache, and we set concurrency to 100 threads.

The Limitations of Google App Engine

Tuesday, June 16th, 2009

I have a very simple test application up on Google App Engine. See gregrluckapphelloworld.appspot.com.

80MB heap limit

Go to gregrluckapphelloworld.appspot.com. Each time you hit is exactly 10MB gets added to Ehcache in-process cache. This is an intentiontal memory leak designed to find out how much you stick in the heap.

The answer is around 80MB. I suspect, taking Jetty into account that there is an -Xmx100m setting in play.

Crashed sites do not recover immediately or start a new instance.Update Feb 2010: Now they do

When you get an OutOfMemory error the site is cooked. There should be some monitoring that notices and takes it down. That is not the case.

I have a wget script which, every 30 seconds, does

while true; do wget "http://gregrluckapphelloworld.appspot.com/"; sleep 30;  done;

The answer is that the dead site stays down for 5 minutes (10 repetitions of my script). And no new instance gets fired up. Your whole site is down.

Update: Google fixed this as of February 2010.

Static content is not distributed through the Google CDN

On the page I put an image. I did not configure it as static. I downloaded it and got the IP 74.125.19.141 which is in Mountain View, California.
I then marked the images as static in appengine-web-app and redeployed.
There was no effect on the serving location or speed of download.
It may be that the files are served from the static content location
You would expect this to be distributed via Google’s CDN.
Here is the header you get from the static content servers.

HTTP/1.0 200 OK
Date: Tue, 16 Jun 2009 09:47:01 GMT
Expires: Tue, 16 Jun 2009 09:57:01 GMT
Cache-Control: public, max-age=600
Content-Type: image/jpeg
Server: Google Frontend
Content-Length: 237952
Connection: Keep-Alive

Another interesting thing – cache expiry is set to 10 minutes. A CDN will normally set the TTL longer and rely on a technique such as resource renaming to overcome browser cache issues.

Conclusion

None of this is good. The first is a very serious limitation. The last two are killers for running a production app. Hopefully Google will fix these things.

Ehcache 1.6.0 is now compatible with Google App Engine

Tuesday, June 16th, 2009

The forthcoming Ehcache 1.6.0 is compatible and works with Google App Engine. You can get it now from ehcache snapshots.
Google App Engine provides a constrained runtime which restricts networking, threading and file system access. All features of Ehcache can be used except for the DiskStore and replication. Having said that, there are workarounds for these limitations.

Why use Ehcache with Google App Engine?

Ehcache cache operations take a few ?s, versus around 60ms for Google’s provided client-server cache memcacheg (as reported on cloudstatus.com). Because it uses way less resources, it is also cheaper.
You can also store non-Serializable objects in it. And finally there is the rich Ehcache API that you can leverage.

Recipes

Setting up Ehcache as a local cache in front of memcacheg

The idea here is that your caches are set up in a cache hierarchy. Ehcache sits in front and memcacheg behind. Combining the two lets you elegantly work around limitations imposed by Googe App Engine. You get the benefits of the ?s speed of Ehcache together with the umlimited size of memcached.
Ehcache contains the hooks to easily do this.
To update memcached, use a CacheEventListener .
To search against memcacheg on a local cache miss, use cache.getWithLoader() together with a CacheLoader for memcacheg.

Using memcacheg in place of a DiskStore

In the CacheEventListener , ensure that when notifyElementEvicted() is called, which it will be when a put exceeds the MemoryStore’s capacity, that the key and value are put into memcacheg.

Distributed Caching

Configure all notifications in CacheEventListener to proxy throught to memcacheg.
Any work done by one node can then be shared by all others, with the benefit of local caching of frequently used data.

Dynamic Web Content Caching

Google App Engine provides acceleration for files declared static in appengine-web.xml.
e.g.




You can get acceleration for dynamic files using Ehcache’s caching filters as you usually would.

Getting Started

To get started see the Ehcache with Google App Engine HowTo.