We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Processing as a web service.
Page Index Toggle Pages: 1
Processing as a web service. (Read 1494 times)
Processing as a web service.
Jan 17th, 2008, 11:28pm
 
I'd like to try to use processing programs as both an embedded applet, and as a web service (I imagine some sort of user-controllable preference to toggle between the two).

Naturally, the applet side of things works great. Instead, I'm having trouble figuring out how to have Processing *not* create a display window, so that I can hook the processing program into a simple CGI script and dump the image through that.

How can this be done? I see that the built-in PDF renderer allows this, but I'm shooting for the output being raster images like PNGs, and not PDFs.

Preferably, I'd avoid having to do too much Java hacking to make this work, but I do know a reasonable amount of Java and it wouldn't be out of the question.
Re: Processing as a web service.
Reply #1 - Jan 21st, 2008, 2:07am
 
I think the technical term for that is a headless display...

See this thread:
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Suggestions;action=display;num=1193317878;start=9#9
Re: Processing as a web service.
Reply #2 - Jan 22nd, 2008, 12:50am
 
Wow, Micke, you're getting deep into Processing now? Sweet.

The thread Aleck referred you to gives some basic info. Basically, you'd need to use pure Java AWT and override both PApplet and PGraphics so that they didn't open windows. It'd be fairly difficult. You might be able to use PGraphicsJava2D from a regular Java class without a PApplet. But it'd be pretty experimental.

Re: Processing as a web service.
Reply #3 - Jan 22nd, 2008, 1:12am
 
I haven't had a chance to try the techniques discussed in the thread that alecks mentioned yet, but I'll be getting into those probably tomorrow.

For a quick-and-dirty solution, I liked the sound of using Xvfb, so I'm going to start there. I'd ideally like to leave most of the Processing internals alone, because I still want to be able to take advantage of the web applets and standalone applications without having to do further special-casing or monkeying with the code.

Nevertheless, I'm going to give some of those other ideas a try after Xvfb. I'll post results soon.
Re: Processing as a web service.
Reply #4 - Jan 26th, 2008, 11:36am
 
I finally had a chance to test out Processing as a web service using Xvfb, and it works great, but with some caveats.

For this test, I coded a simple program that draws an ellipse against a white background, at a resolution of 600x600. I wrote it outside of the Processing IDE (vim, make, and the Java SDK that ships with OS X, for the curious), compiled it, and set it to run as a web service by wrapping it in a shell script and stuffing it into a directory that Apache2 could serve it from. The program is encoding the image as a JPEG, and dumping out a content type header and the encoded bytes to stdout, so that the script can be used inside of an img tag.

It's not exactly fast. Even on a dedicated machine (I set up a Gentoo server specifically for this test), it was still taking a second or more to serve one request. I suspect some of this may have to do with the way I'm doing JPEG encoding, so I'll have to try some optimizing and see what happens.
Re: Processing as a web service.
Reply #5 - Jan 26th, 2008, 1:52pm
 
nice!

one thought: is the jvm starting up for each request? if so this certainly is the bottleneck ..

F
Re: Processing as a web service.
Reply #6 - Jan 27th, 2008, 2:13am
 
Yes, it's starting up for each request.

I'd thought that one could start the Processing program as a service (just like Xvfb), then use some IPC to get data out of it instead, but that sounds like a threading nightmare waiting to happen.

Are there other ways of keeping the JVM warmed up, other than just keeping the program running?
Re: Processing as a web service.
Reply #7 - Jan 28th, 2008, 3:17pm
 
You might try keeping another program running in the background, that should keep the JVM from unloading.  Even something real simple, as long as it doesn't eat much CPU or exit.

But I don't know how much time you're going to lose from starting your particular process over and over again...how fast does this need to be?
Page Index Toggle Pages: 1