Is it possible to have the Memcached Service running in a Web Role?

Apr 21, 2010 at 4:22 PM

It would be awesome to take advantage of the free memory in the web roles!

Apr 21, 2010 at 5:11 PM
I may be possible to do this but if you are looking to use cache at the web level you may just want to use System.Web.Cache. What type of scenario are you looking to create? I would imagine it might be because you may want to get more value for the buck spent on the web roles and having the web-roles become memcached hosts as well as HTTP/S hosts gives you more memory. Or is it that you want a cluster of webroles to be both web/memcached stores. I think you can accomplish this using similar code that is in the web worker role project (if you should or not is a different story I'd have to know more). Basically take the startup code from the worker role and put it into ApplicationStart() of the WebRole.cs and ensure that you include the executable. You may also have to open extra ports given your configuration. Let me know if you need further assistance, I may be able to put together a separate project.
Apr 21, 2010 at 9:00 PM

So, my using System.Web.Cache is not usefull when you have 150 web role instances running, you most likely  won´t be finding the object in the local cache, so that's why it would be great be distributed cache. And yes, my idea is to have a mix of Web (HTTP) host together with memcached host so as to utilize the free memory on this instances (web roles usually have a lot of unsed memory, at least in my case).

It would be awesome to have a sample project for doing this!


Also, shouldn´t you be using a 64 bits version of memcached instead of the 32 bits version you are using?

Apr 23, 2010 at 12:19 AM
Edited Apr 23, 2010 at 12:19 AM

WebRole = Memcached Role:

I attempted to put together an example project, however, the core reason this can not work is that a WebRole can only host via three ports all of which are bound to HTTP based traffic. You have HTTP, HTTPS, and Internal Endpoint only exposing 1 HTTP endpoint.

The attempt I made was to try to turn on the internal endpoint to allow all the machines to communicate with each other (kind of a pre-req for the 'distributed' part of 'distributed' cache) - but this port is restricted to the http protocol, sadly.

So at least for now you can't host anything other than HTTP/S based stacks in a WebRole and must purchase a WorkerRole (who can host on any port). This is probably the key difference between the two. So at the end of the day we can host a memcached instance in a webrole, we just can't get that host exposed to other instances. Which makes it no more effective than running with System.Web.Cache.

As for 64bit:

The 64 bit versions of memcached do not work in Azure as of yet. It has to do with the process model. There is currently only one version that works. When Azure supports the 64 bit we should be able to use the latest release of memcached.