How to keep LC server stay open?

Bringing the internet highway into your project? Building FTP, HTTP, email, chat or other client solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

How to keep LC server stay open?

Post by [-hh] » Fri Oct 31, 2014 11:13 pm

Recently I tried LC server. The dominating problem I encountered:
Every time when a file, that uses "lc", is interpreted by the webServer (Apache), a new instance of the LC server is loaded. Such a startup is *very* slow (compared for example to php).

Is there a way to have a LC server already open (for example start once with Apache and mySQL) and have it stay open to do the tasks delivered by the webServer?
shiftLock happens

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: How to keep LC server stay open?

Post by FourthWorld » Sat Nov 01, 2014 1:02 am

This is how CGI usually works: Apache calls an app via its command-line (whether it's Perl, or Python, or PHP, or LiveCode, or something else), a new instance is launched to handle the request, and once handled it dies.

This multi-processing is in some ways slightly less efficient than multi-threaded, but much easier to program for and in some contexts more secure.

Given the complexity of good thread management, personally I don't mind the minimal additional overhead of CGI.

If you really want a daemon implementation you could craft one with a standalone, opening a socket and writing an Apache mod to communicate to it. But without threading it would be difficult to handle multiple requests efficiently, requiring queuing and yielding slower performance under load than the multi-processing CGI gives us for free.

How long were the startup times for PHP and LiveCode Server?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: How to keep LC server stay open?

Post by [-hh] » Sat Nov 01, 2014 2:17 am

In average -- 100 runs with 10 diff files -- on Mac mini (2.5 GHz, Apache 2.4, php7).

php startup 40 ms + 40 ms for medium script
LC6 startup 250 ms + 40 ms for medium script
LC7 startup 900 ms + 80 ms for medium script

Probably some parts of these LC-times are due to the fact that my scripts are not (yet) optimized for LC server.

[Edit. Corrected: All timing had one zero too much. Sorry.]
Last edited by [-hh] on Sat Nov 01, 2014 9:44 pm, edited 1 time in total.
shiftLock happens

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: How to keep LC server stay open?

Post by FourthWorld » Sat Nov 01, 2014 3:07 am

Is your PHP running as CGI, FastCGI, or using mod_php?

Edit: how are you measuring speed?

To take other factors out of the equation and focus on LC engine load time, I made a very simple script (I rename the engine "lc7-server" to make it easier for me to work with in Terminal:

Code: Select all

#! /home/rgu/Downloads/lc-server/lc7-server

put "Hello World" & the millisecs
quit
Then I ran it the script with the "time" command - here are the results:

Code: Select all

rgu@rg-ubu:~/Downloads/lc-server$ time ./lc-test
Hello World1414808422368
real	0m0.044s
user	0m0.024s
sys	0m0.020s
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: How to keep LC server stay open?

Post by [-hh] » Sat Nov 01, 2014 9:49 pm

First of all thanks for your efforts.

Your timing made me look again at what I've written and I've corrected it above (was one zero too much; I was obviously too tired at two o'clock in the morning ...).

My "timing files" are lost from restoring a full backup after testing LC 7 and LC7 server (what crashed several times the OS). But I can remember, at about, what I put in. I'll come back in a few days.

I don't use fastCGI for php but mod_php. And LC server is installed according to the (fine) Tutorial.
shiftLock happens

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: How to keep LC server stay open?

Post by FourthWorld » Sat Nov 01, 2014 10:19 pm

FWIW, this morning I needed to do some server benchmarking and finally found a way to get peak memory usage in addition to timing info (I'd been looking for that for a long time but it seem my googlefu eluded me until now).

The trick turns out to use the /usr/bin/time program as opposed to the time command, adding the -v (verbose) option. For CGIs you also need to create vars for REQUEST_URI and any others you script will use, and remember to export them so your CGI can see them - in my case the full command was:

Code: Select all

SCRIPT_FILENAME="evoc.cgi"; export SCRIPT_FILENAME; REQUEST_URI="features"; export REQUEST_URI; /usr/bin/time -v ./evoc.cgi
In that case evoc.cgi is a text file with a shebang that specified a LiveCode Linux standalone rather than LC Server. Still, the load times and memory should be very similar, and here that script (which also drives the livecodejournal.com site) takes about 22 ms to run with a peak memory load of about 2.5 MBs.

IIRC my standalone was made with v6.6 rather than 6.7, but I would expect the stats to be in the same ballpark, with v7 a little heavier with all the Unicode stuff.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply