Cluster Scope

The following description should help you to use the new cluster scope, introduced in Railo 3.0 (Beta). The description is based on MacOSX, but it should work for Windows and Linux as well.

Let's start. First download Railo Express 3.0 Beta from our Website at
www.railo-technologies.com/en/index.cfm?treeID=361

Copy the content of the downloaded zip to a folder of your choice, rename it to railo8888 and make a second copy named railo9999, so that you end up with to folders containing the railo express content.


Change to folder "railo9999".


Open the file server.xml and change the port definition on line 16 from 8888


to 9999.


Start both Railo application servers, (double) click start[.bat] in both folders (railo8888 and railo9999).


Two command prompts should open.


Now change to your browser and tip. http://localhost:8888/railo-context/admin/server.cfm


Enter a password for your server administrator.


Change to page Remote/Security Key.


Copy the Security Key.


Now open a second browser window and open the url. http://localhost:9999/railo-context/admin/server.cfm


Change to page Remote/Clients.


click on


Fill the form as follows (but use your server password and your security key), then save it.


Change to page Remote/Security Key.


Copy the Security Key.


Change back to the other browser (http://localhost:8888/railo-context/admin/server.cfm) and create the same client in this server administrator, but this time with the other security key and the server "http://localhost:9999".


You will now have a bidirectional connection between the two Railo application servers.

Go now to the webroot folder of one of the two Railo server, for example the railo8888 folder, and open the index.cfm file.


Remove the content and add the following code.


your are on:
<cfdump var="#cgi.SERVER_PORT#">
<cfset cluster["port"&cgi.SERVER_PORT]="Hello from "&cgi.SERVER_PORT>
<cfdump var="#cluster#">


Do the same for the other Railo server. If you changed the index.cfm file in railo8888 the change now the one in railo9999.



your are on:
<cfdump var="#cgi.SERVER_PORT#">
<cfset cluster["port"&cgi.SERVER_PORT]="Hello from "&cgi.SERVER_PORT>
<cfdump var="#cluster#">


Go back to the first browser and call http://localhost:8888/. You should see that you have requested railo 8888 and that this instance of the Railo server has written the key "port8888" to the cluster scope.


Open or go back to the second browser and request http://localhost:9999/. This time you are on the railo 9999 instance and you should see both values in the cluster scope, from port8888 and port9999.


voilà you have it!

now stop one railo with stop[.bat], for example railo 9999


and call the other railo in browser
If you stopped railo9999, request http://localhost:8888/. You should see that the cluster scope still shows the two entries.


Because railo9999 is not running, railo8888 can not synchronize the cluster scope. Go to the Railo administrator of the railo8888 instance http://localhost:8888/railo-context/admin/server.cfm and go to Services/Tasks.


In the list you will see one open task, select it and open the detail view.


In the detail view you will see that Railo tried to synchronize the requests. The synchronization failed because the second Railo instance is not available.


Restart railo9999 again and call it in a browser. You will see that railo9999 already took the scope data from the other server instance.


Go back to Services/Tasks list in the Railo administrator. You will see that the open taks is gone.


When you invoke the cluster scope the first time after restarting the server instance, Railo asks the connected instance for the cluster data. This means that you don't need to wait for the synchronisation.

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Andrew Grosset's Gravatar Could this be used to synchronise application variables across two servers not necessarily in a cluster eg forums.mywebsite.com on one server and mywebsite.com on an other server? The application struct I'm thinking of is dynamic/constantly changing and I need to find a way to ensure each server has the same application struct.
# Posted By Andrew Grosset | 17.09.09 19:29
Gert Franz's Gravatar Well yes and no. We are working on something called "applicationstorage" that might solve exactly this problem. You CAN use the cluster scope in order to synchronize your application scope, but if the application scope is quite big it get's very slow. And in addition the cluster scope only contains simple values so you need to serialize the scope every time you want to synchronize it.

Gert
# Posted By Gert Franz | 18.09.09 11:11
Andrew Grosset's Gravatar "applicationstorage" - that's interesting. In the mean time I'm using memcache to synchronise some application variables across two different railo installs on my devlopment pc (railo express) so far it seems to be working!

Andrew.
# Posted By Andrew Grosset | 23.09.09 02:14
Gert Franz's Gravatar Andrew,

may I ask how you do this?

Gert
# Posted By Gert Franz | 23.09.09 07:14
Gert Franz's Gravatar @all: this comment is only since I accidentially deleted Andrew's comment:

Two servers: server A and server B.

When user logs in to server A his session is also stored in memcache.
On server A I use an "onClick" javascript url to call via ajax a function to check if user's session is current (logged in).
If it is I create a string: getTickcount and users session.id and encrypt it and call it "token". I return this to the calling page where a javascript function builds a form and places the token in the form and submits it to server B. In the onRequestStart of application.cfc (server B) if "form.token" is detected it is passed to a function that decrypts the token, checks the time difference (compares getTickcount is less than 500ms) and if the user does not already have a session on server B checks memcache for this users session if it is available then the session struct is copied from memcache to server B's session struct and the user is logged in on server B.

One drawback to this: when you store something in memcache you give it an expiry time say 20 mins and this doesn't change unless you set the value to memcache again, compare this to a session value of 20mins: if you hit the server every 19mins the session will never expire so I just give memcache a longer expiry time.

The same principal can be used to duplicate application variables across from server A to server B. As long as you update memcache whenever you change the application (or session) struct then you can keep the user synchronised across the two servers.

I have not exhaustively tested this yet as I'm still developing/testing the idea, but so far its ok.

Andrew.

PS
memcache for coldfusion has been developed by Jon Hirschi http://www.flexablecoder.com

It can be downloaded here: http://cfmemcached.riaforge.org
# Posted By Gert Franz | 24.09.09 01:01
BlogCFC was created by Raymond Camden. This blog is running version 5.9.1.002. Contact Blog Owner