[Opensim-dev] Is it OK performance-wise to long-poll a money module?

Edmund Edgar ed at avatarclassroom.com
Sat Sep 15 04:07:31 UTC 2012


I've got a situation with the money module I'm working on where I'd
like an external program (running on the client PC in parallel to the
viewer) to be able to be in almost constant contact with the server
while the user is logged in. (I want it to be able to find out
whenever the user wanted to buy something.)

I figure I can do this by having the external program long-poll the
OpenSim server. (The external program makes a request, the server
waits such time as it has something to tell the external program, then
responds. It gives up and responds if there's nothing to say after 30
seconds or so, at which point the external program will make a new
request and start the cycle again.)

At this point if I was serving a web application with Apache I'd start
worrying that I was hogging a bunch of threads and eating through the
memory. Is this the kind of thing I should be worrying about with
OpenSim, or can I merrily go ahead and long-poll without worrying?

The kind of thing I'm thinking of follows:


public void FirstRegionLoaded ()

	MainServer.Instance.AddHTTPHandler ("/checkfortransactions/",
CheckForTransactions);

}

public Hashtable CheckForTransactions(Hashtable request) {

	UUID userUUID = (get a user id using a session ID passed in the
request or something);

	int i;
	// poll for 30 seconds then give up
	for (i=0; i<30; i++) {
		if (m_transactionsAwaitingNotification.containsKey("userUUID")) {
			// Reply to the request
			Hashtable reply = new Hashtable ();
            		reply["int_response_code"] = 200;
            		reply["str_response_string"] = "{ Some JSON goes here }";
            		reply["content_type"] = "text/json";
			return reply;			
		}
		Thread.Sleep (1000);
	}

	Hashtable reply = new Hashtable ();	
	reply["int_response_code"] = 204; // No Content
	return reply;	

	// The client will get this reply then hit /checkfortransactions/ again.

}

PS. Thanks for the replies to my C#-ignorant questions on previous threads.

-- 
Edmund Edgar
Avatar Classroom
Your classroom, on the web, in a virtual world.

ed at avatarclassroom.com
+81 090 3912 3380
Skype: edmundedgar
Second Life: Edmund Earp
Linked In: edmundedgar
Twitter: @edmundedgar
http://www.avatarclassroom.com



More information about the Opensim-dev mailing list