TomcatExpert

Scalable, Cloud-friendly Apache Tomcat Sessions with RabbitMQ: Part II

posted by jbrisbin on July 1, 2010 06:12 AM

In my first article on taking advantage of RabbitMQ's asynchronous messaging to implement a cloud-friendly session manager, I covered the method behind the madness and introduced you to some of the functions a session manager has to perform in the course of doing its job. In this, the second of two articles covering this topic, I'll describe how loading and updating session objects is handled and, in the interest of fairness, give some disclaimers and acknowledge the trade-offs made to get here.

The Code (at 1,000 feet) cont'd

Whenever code wants to interact with a user session, whether that be to load it into its own memory or to replicate attributes on that session, it sends these messages to a queue whose name contains the session ID. The pattern used to create the queue name is configurable so you can partition user sessions by application, or even by something more fine-grained (without resorting to using multiple, non-clustered RabbitMQ servers).

The session store first checks its internal Map to see if the requested session happens to be local to this store. If it is, the store simply hands that session back to the manager. If it's not, then the store sends a "load" message to the session's queue. It doesn't just fire off a message, though. It turns out that a user's session can be requested from the store many times during the course of a request. If one were to send a load message every time this happens, then we would see a serious performance degradation. To get around this, before a load message is sent, the store checks to see if it's already trying to load this session. If it is, it simply waits until that process is finished and uses the session being loaded in that other thread.

Whatever is listening on the session queue responds to the requestor with a serialized version of the session object. For the purposes of failover, it would be good to have some replication queue listeners that kept a copy of all the session objects so that load messages don't go unanswered if the original Tomcat server on which the user's session was in memory dies or is stopped. There is some rudimentary support for sessions to be replicated off the server on which they exist whenever they are created or when attributes are set or removed from them. The process used to manage this replication and failover, though, is beyond the scope of this discussion.

The store or replication listener that has a subscriber listening to the session's queue will serialize the session object and send an "update" message back to the requestor. The update message comes back into the main event handler, which doesn't know anything about loading sessions. It simply dumps the message into an UpdateEventHandler, which is responsible for checking to see if anyone is currently waiting on this session to be loaded. If it is, it hands that session off and lets those other threads continue on their merry way.

The First Caveat

It's at this point I have to caveat what I said last time about only having one session that is available to the cloud. There is a mode of operation that allows for leaving session objects on every server that user session has touched. If the user goes back to that server, then their session will still be local to that box and the store will have a lot less work to do. But any time there's a need for replication, there's an exponential increase in headaches to keep things updated. Since we haven't personally needed this to work, we haven't spent a lot of time fleshing out how it should.

The Bleeding Edge Speech

There's a reason your boss doesn't want you to run bleeding edge software. Doing so can be painful. This session manager hasn't seen widespread adoption, hasn't been battle-tested, and is the only child of a proud, but over-worked single father. It's not for the faint-of-heart. That said, hybrid, private clouds are an area of our industry poised for explosive growth in the next couple of years. The more companies that deploy dynamic, private clouds, the more developers will come knocking, looking for ways to solve the complex problems introduced by a highly-virtualized and highly-dynamic cloud environment. Having an 8-CPU box does you no good if you only have one server running multiple threads. In order to make full use of those resources, you need to spread the load across those CPUs by loading it down with lots of little processes. Being able to load-balance across those Tomcat instances without resorting to sticky sessions has been the driving force behind the development and adoption of this session manager.

Nothing is perfect and neither is this particular solution. In order to gain flexibility, we've had to trade-off in-memory caching. In order to get a tailor-made solution, we've had to trade-off stability of the codebase. We don't mind bleeding a little if we're confident we'll be better off in the end. Not everyone will be so bold.

As mentioned in the first article, I have made all of the code for this session manager available on Github under the Apache 2.0 license. Patches are encouraged and welcomed!

Jon Brisbin is an Architect/Analyst/Java Guru at NPC International, the world's largest Pizza Hut franchisee. He's been deploying web applications on Tomcat for over 10 years and currently focuses on cloud computing (virtual, hybrid, and private). He built a private cloud from scratch using VMware ESX, Ubuntu Linux, packing tape, and rusty baling wire. He's done consulting work with industry leaders and Mom-and-Pops alike. Prior to NPC, Jon developed new application frameworks, integrated the AS/400 with UNIX and Windows systems, developed Lotus Domino applications, hacked websites together with Perl CGI and a text editor, and served with US Air Force Intelligence in a very hot and sandy, but undisclosed, location. He lives in the rural Midwest.

He blogs on Web 2.0 (and sundry topics) on his website: http://jbrisbin.com/web2

Comments

You have clearly described

You have clearly described about Apache Tomcat sessions with RabbitMQ. I think this is a wonderful opportunity for most of the people to know much about this topic. I am very much satisfied on this article! cleaning service san jose

8 ball pool hack I really

8 ball pool hack I really appreciate this wonderful post that you have provided for us. I assure this would be beneficial for most of the people. clash of clans hack deutsch

Hello there! I simply wish to

Hello there! I simply wish to offer you a big thumbs up for your excellent info you have got right here on this post. I am coming back to your blog for more soon.
Mortgage Broker Calgary

thanks for j sharing with

thanks for j sharing with that awesome articles thanks u a lot
rasoio elettrico | regolabarba | ferro da stiro con caldaia | Friggitrice ad Aria | scopa a vapore | ripetitore wifi | ripetitore wifi amplificatore wifi piastra a vapore | miglior aspirapolvere | skateboard elettrico | passeggino leggero | miglior smartphone | tablet per bambini uyrr

Your web site doesn't render

Your web site doesn't render correctly on my iphone 3gs - you may wanna try and repair that
Edmonton Mortgage Broker
Life Insurance Vancouver
Life Insurance Calgary

Alex

Certainly, this approach found others planning any alternative workout sessions really are best to many of united states so, who look for by ouselves while traveling or possibly experience modest appliances alternate options. Get More Info

Bon Voyage Sedan

Beaver says I also have such interest, you can read my profile here:
shuttle service to cruise terminal Long beach

Extremely fascinating online

Extremely fascinating online journal. Alot of websites I see nowadays don't generally give anything that I'm keen on, yet I'm most definately intrigued by this one. Recently believed that I would post and let you know. insect control

I haven’t any word to

I haven’t any word to appreciate this post.....Really i am impressed from this post....the person who create this post it was a great human..thanks for shared this with us.
alcohol abuse

Alex

Certainly, this approach found others planning any alternative workout sessions really are best to many of united states so, who look for by ouselves while traveling or possibly experience modest appliances alternate options. college papers for free

Jual Laptop Notebook PC HP Lenovo Printer Tinta Toner Epson Mura

In your blogging, it will be sharp you will be the perfect guy to help you about as much as possible authoring. Jual tinta Printer

Your site has grown a

Your site has grown a one-stop find as much as possible tutorial authoring. Thanks for your time in the very good get the job done. As i tested the online sites one preferred and even On the net which will best-dissertation.pores and skin look though. Ones own get the job done is kind of exemplary. Women’s Clothing

Unsere Hände arbeiten jeden

Unsere Hände arbeiten jeden Tag für uns, dennoch kommen sie in der Pflege oftmals viel zu kurz Wir bieten erfolgreich unseren Kunden perfekte Maniküre und Pediküre Shellac Behandlung in Berlin Maniküre Berlin

jhon

Prepare even more article content on this subject niche you now have a truly great suggestion that will persuade writters. fire sale

I have bookmarked your blog,

I have bookmarked your blog, the articles are way better than other similar blogs.. thanks for a great blog!
backpack

Kirk Hammett Guitar Setup.

Kirk Hammett Guitar Setup. Hammett's guitar apparatus and setup is one of the more different in the realm of metal music. That comes as somewhat of an unexpected perceiving how his tone, and the tone of Metallica all in all, hasn't significantly changed.
Kirk Hammett Guitar Setup

I am happy to find this post

I am happy to find this post Very useful for me, as it contains lot of information. I Always prefer to read The Quality and glad I found this thing in you post. Thanks
foreclosures

It was a very good post

It was a very good post indeed. I thoroughly enjoyed reading it in my lunch time. Will surely come and visit this blog more often. Thanks for sharing.
Trickprime

This is such a great resource

This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free.
Murray Utah SEO Audit

This is a great article

This is a great article thanks for sharing this informative information. I will visit your blog regularly for some latest post.
SEO Salt Lake City

Great Article it its really

Great Article it its really informative and innovative keep us posted with new updates. its was really valuable. thanks a lot.
pug stuffed animal

Cool stuff you have got and

Cool stuff you have got and you keep update all of us.
best laptop for producing music

It proved to be Very helpful

It proved to be Very helpful to me and I am sure to all the commentators here!
gaming laptops under 400

I am very much pleased with

I am very much pleased with the contents you have mentioned. I wanted to thank you for this great article.
The Language of Desire

Great article Lot's of

Great article Lot's of information to Read...Great Man Keep Posting and update to People..Thanks
Ductless mini split air conditioners

Thanks for sharing nice

Thanks for sharing nice information with us. i like your post and all you share with us is uptodate and quite informative, i would like to bookmark the page so i can come here again to read you, as you have done a wonderful job.
slitheriohackcheats.online

jackman10

This article gives the light in which we can watch the truth. This is exceptionally pleasant one and gives indepth data. A debt of gratitude is in order for this pleasant article. double watch winder Much obliged to you for such an elegantly composed article. It's loaded with adroit data and captivating depictions. Your perspective is the best among numerous.

jackman10

I was taking a gander at some of your posts on this site and I consider this site is truly informational! Keep setting up.. skull bracelet I have been looking at a couple of your stories and i can state really well done. I will bookmark your online journal

jackman10

I as of late went over your website and have been perusing along. I thought I would leave my first remark. I don't comprehend what to say aside from that I have delighted in perusing. Decent blog, I will continue going to this online journal frequently. fashion accessories Keep doing awesome read few posts on this site and I imagine that your online journal is exceptionally fascinating and has sets of phenomenal data.

carissa30

I really loved reading your blog. It was very well authored and easy to undertand. Unlike additional blogs I have read which are really not tht good. I also found your posts very interesting. In fact after reading, I had to go show it to my friend and he ejoyed it as well! our blog

Fantastic blog! Do you have

Fantastic blog! Do you have any tips and hints for aspiring writers? I’m planning to start my own website soon but I’m a little lost on everything. Would you propose starting with a free platform like WordPress or go for a paid option? There are so many options out there that I’m completely overwhelmed .. Any suggestions? Many thanks!
EDDM postcard printing

Coach Rental For Schools Trips

With VIP Coach Use it's possible you'll journey in deluxe and acquire there in sort. Our multi-award prosperous organization features a robust number of VIP autos.Coach Rental For Schools Trips

carissa30

This type of message always inspiring and I prefer to read quality content, so happy to find good place to many here in the post, the writing is just great, thanks for the post. check this post Great knowledge, do anyone mind merely reference back to it

This site is really very

This site is really very helpful for me. From this I understood more about the cloud friendly apache tomcat sessions. It is very good that you have shared the details about the code and other important topics related to it. sfx makeup artist

Robinjack

Nice Informative Blog having nice sharing.. winter gear

Robinjack

This type of message always inspiring and I prefer to read quality content, so happy to find good place to many here in the post, the writing is just great, thanks for the post. apparel

Robinjack

Your music is astounding. You have some extremely capable specialists. I wish you the best of accomplishment. winter gear

Robinjack

I really like your writing style, great information, thankyou for posting. clothing

An interesting dialogue is

An interesting dialogue is price comment. I feel that it is best to write more on this matter, it may not be a taboo topic however usually individuals are not enough to talk on such topics. To the next. Cheers.
des moines tattoo

I really loved reading your

I really loved reading your blog. It was very well authored and easy to understand. Unlike other blogs I have read which are really not that good.Thanks alot!
here

Robinjack

I have perused a couple of the articles on your site now, and I truly like your style of blogging. I added it to my top choices online journal website list and will be inquiring soon. If it's not too much trouble look at my site also and let me realize what you think. designer clothes

Robinjack

Great post however I was thinking about whether you could compose a litte more on this subject? I'd be extremely appreciative on the off chance that you could expand a tiny bit further. Welcome it! wearables

Interesting and amazing how

Interesting and amazing how your post is! It Is Useful and helpful for me That I like it very much, and I am looking forward to Hearing from your next.. procrastination quotes

Thank you for some other

Thank you for some other informative website. The place else may just I get that kind of information written in such a perfect method? I have a venture that I am simply now running on, and I’ve been at the glance out for such info. Biographies of missionaries

Session is a very important

Session is a very important and vast topic, and its codes are very difficult when comparing with others. Dealing with session needs much knowledge and the article given here explains all the important details about sessions that are used in Apache Tomcat. medical billing companies in new jersey

Dental Emergency Care Services

Many people have to have at the very least a person tooth filling in their life time. Dental fillings are most often utilized to take care of cavities. Dental Emergency Care Services

thomasqq

What we realized can be appropriate, recognize you must separate your connect involving active tangible along with brand-new. You have to be mindful if you take care of your tangible with the partitions, since in any other case you will find there's possibility to separate. It usually is greater to have the support associated with an pro. rebelmouse.com

That are definitely

That are definitely excellent. Many of these tiny details are made getting lot of background knowledge. I am interested in them plenty. custom written dissertation

It is perfect time to make

It is perfect time to make some plans for the future and it is time to be happy. I've read this post and if I could I desire to suggest you some interesting things or suggestions. Perhaps you could write next articles referring to this article. I want to read more things about it!politi fabrizio

Good Information

I think this piece of information is very useful to understand apache tomcat sessions with RabbitMQ. I came to know that these sessions are cloud friendly. Thanks for sharing this information which is very useful to all those who are using tomcat server. luxury event planner

Post new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.