Running a CGI executable constantly

Everything else that doesn't fall into one of the other PB categories.
Seymour Clufley
Addict
Addict
Posts: 1267
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Running a CGI executable constantly

Post by Seymour Clufley »

Some time, somewhere on these fora, I read that a CGI app can run constantly and only "do anything" when a request is made. The poster added that you would need memory allocated to the app for this to work. I've been trying to locate this post without any luck.

Presumably we're talking about a Repeat..Forever loop which looks for changes in the Environment Variables and, if a change has occurred, triggers the procedures that would otherwise run at startup? Please correct me if I'm wrong.

Can anyone please tell me what the terminology is for a CGI app that runs constantly, so that I can google accordingly?

Also, what are the dis/advantages of having a CGI program running permanently?

All help gratefully appreciated,
Seymour.
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

Perhaps you are after FastCGI?
On linux it's a constantly running program, and communicates to the webserver (when the server passes it a request) via a file socket, or network connection.
PHP on linux usually works like this. (on my debian computers anyway)
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post by pdwyer »

On windows this would be ISAPI guess.

I don't recommend it on windows2000 since you would need to restart IIS (all websites) to replace the DLL. On win2k3 I guess ( haven't tested it) that you could just stop that website.

I played with these under powerbasic about 5 years ago, the performance was better than CGI if there were contstant requests.

It shouldn't be too hard to port to PB if you are interested. searching ISAPI on these forums might turn up a PB version for you though - I haven't looked.
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
Seymour Clufley
Addict
Addict
Posts: 1267
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Post by Seymour Clufley »

Thanks for your advice.

The reason I was interested in doing this is it seems silly that my app has to read in data from txt files every time a request is made of it. I thought it would save time if the app was running constantly so it wouldn't need to "learn" everything each time. It's also processing AJAX requests so there will be a lot of requests made of it!

It tends to take 15-30 milliseconds to process a request. I don't know if that's quick or slow as CGI goes, but if it could be reduced that would be handy.

I'm not clear on how to proceed with this... Helpfully, Freak has already ported ISAPI to PB. But what to do with it?!
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post by pdwyer »

I guess this depends on load. If the server is under high load then exe's all the time which have to load data could be a problem. After the first couple of requests though the NTFS drivers (not to mention IIS) will hold you exe's and text files in buffer caches so it will load pretty quickly. Are these text files large and is there processing to be done on them?

If there was high load on the server and using IIS6 I would go with ISAPI. Otherwise I think exe's would be faster and windows servers today have pretty good caching

Maybe you could also have a debug version your exe write log files (if you have just one log file they might lock on the writes so have each exe load choose a unique name) that way for a little extra overhead you could see the load and run times, put the server under more load and see if the caching is doing anything for you.

Maybe write a little multithread load test app that hits your server about 100 times a second and see what happens.

Don't know anything about Ajax except the washing powder. If it's anything java/jboss/coldfusion related then you have bigger perf issues than CGI :x
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
Post Reply