How many instances of the application should XC spawn?

How many instances of the application should XC spawn?

Running TOP on the server gets me this:

12 instances of the main app (Betty47)

op - 20:12:05 up 16:14, 0 users, load average: 0.07, 0.08, 0.09
Tasks: 31 total, 1 running, 30 sleeping, 0 stopped, 0 zombie
Cpu(s): 2.8%us, 3.6%sy, 0.0%ni, 93.5%id, 0.1%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 3973948k total, 2426308k used, 1547640k free, 236488k buffers
Swap: 0k total, 0k used, 0k free, 790248k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
23596 apache 20 0 33636 4636 1972 S 7.8 0.1 0:00.04 index.cgi
23594 apache 20 0 33636 4632 1972 S 5.9 0.1 0:00.03 index.cgi
23595 apache 20 0 33636 4632 1972 S 5.9 0.1 0:00.03 index.cgi
23597 apache 20 0 33636 4632 1972 S 5.9 0.1 0:00.03 index.cgi
21480 apache 20 0 124m 73m 9.9m S 3.9 1.9 0:16.11 Betty47
23598 apache 20 0 33636 4636 1972 S 3.9 0.1 0:00.02 index.cgi
11402 apache 20 0 55952 22m 6896 S 2.0 0.6 2:57.22 PLUS_Meetings
21093 apache 20 0 107m 67m 9.9m S 2.0 1.7 0:05.08 Betty47
4305 apache 20 0 54724 17m 5976 S 0.0 0.4 2:57.95 Load
18676 apache 20 0 104m 64m 14m S 0.0 1.7 3:41.18 rcfeC
20025 apache 20 0 50868 18m 6548 S 0.0 0.5 0:04.00 launcher
20715 apache 20 0 97860 55m 9260 S 0.0 1.4 0:00.96 Betty47
20731 apache 20 0 97856 55m 9260 S 0.0 1.4 0:00.94 Betty47
20750 apache 20 0 97864 55m 9208 S 0.0 1.4 0:00.42 Betty47
20766 apache 20 0 97856 55m 9260 S 0.0 1.4 0:00.95 Betty47
20782 apache 20 0 97856 55m 9260 S 0.0 1.4 0:00.96 Betty47
20811 apache 20 0 97888 55m 9300 S 0.0 1.4 0:01.07 Betty47
20907 apache 20 0 97864 55m 9224 S 0.0 1.4 0:00.38 Betty47
20957 apache 20 0 97860 55m 9224 S 0.0 1.4 0:00.38 Betty47
20981 apache 20 0 98.1m 57m 9.8m S 0.0 1.5 0:01.75 Betty47
22906 apache 20 0 33636 4716 1992 S 0.0 0.1 0:00.03 index.cgi
22915 apache 20 0 33636 4716 1992 S 0.0 0.1 0:00.03 index.cgi
22933 apache 20 0 33636 4712 1992 S 0.0 0.1 0:00.03 index.cgi
23075 apache 20 0 33636 4712 1992 S 0.0 0.1 0:00.04 index.cgi
23165 apache 20 0 33636 4716 1992 S 0.0 0.1 0:00.03 index.cgi
23182 apache 20 0 33636 4712 1992 S 0.0 0.1 0:00.03 index.cgi
23193 apache 20 0 33636 4716 1992 S 0.0 0.1 0:00.04 index.cgi
23358 apache 20 0 33636 4712 1992 S 0.0 0.1 0:00.03 index.cgi
23572 apache 20 0 257m 205m 12m S 0.0 5.3 34:03.81 Betty47
23590 apache 20 0 33636 4700 1980 S 0.0 0.1 0:00.03 index.cgi
23593 apache 20 0 14888 1104 880 R 0.0 0.0 0:00.01 top

There should only be one instance of each app in memory at any given time.

Completely restarted the serve and made a single connection to the separate XC server.

Why are all those index.cgi being spawned?

2015-10-29 20:54:18

top - 20:54:18 up 4 min, 0 users, load average: 0.36, 0.18, 0.07
Tasks: 9 total, 1 running, 8 sleeping, 0 stopped, 0 zombie
Cpu(s): 11.4%us, 7.0%sy, 0.0%ni, 73.8%id, 5.8%wa, 0.0%hi, 0.0%si, 1.9%st
Mem: 501064k total, 477044k used, 24020k free, 10768k buffers
Swap: 523260k total, 0k used, 523260k free, 191292k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1547 apache 20 0 53692 17m 5932 S 0.0 3.5 0:11.77 Load
1640 customer 20 0 112m 64m 9.8m S 0.0 13.2 0:01.34 Kirill3
1974 apache 20 0 33636 4608 1948 S 0.0 0.9 0:00.04 index.cgi
2049 apache 20 0 33636 4688 1968 S 0.0 0.9 0:00.04 index.cgi
2064 apache 20 0 33636 4612 1948 S 0.0 0.9 0:00.04 index.cgi
2068 apache 20 0 33636 4616 1948 S 0.0 0.9 0:00.04 index.cgi
2119 apache 20 0 33636 4688 1968 S 0.0 0.9 0:00.04 index.cgi
2190 apache 20 0 33636 4680 1956 S 0.0 0.9 0:00.04 index.cgi
2192 apache 20 0 14888 1068 860 R 0.0 0.2 0:00.01 top

Problem solved.

The MySql plugin that ships with Xojo is the culprit. It does not allow multiple queries to the database. I you have multiple queries it will crash in such a way that when the next request comes in will spawn a new instance of the application.

Eventually all the instances will choke the server.

We wrapped every single interaction with the MySql BD in “Critical Section” and the problem has disappeared. We did this a few weeks ago and all our crashes and multiple instance have stopped.

You have one instance used by many sessions ?
Thats definitely going to have issues

Using a critical section guarantees that your app will be throttled on that one connection as well
You’d be better of with one connection per session

@Norman Palardy Thanks for the help. But your help raises two more questions, so I am afraid I will have to ask for more help.

  1. It appears that Gregs answer is at odds with yours. Explain?
  1. You are correct the critical section it throttles my database queries. But since the Plugin is the cause of the crash. and it works around a bug that only Xojo Inc can fix: What would you suggest I do about it? (or am I missing something?)

One instance of the app itself, but each request from a browser will launch its own index.cgi file.

Greg is talking about instances of the app. Norm is talking about something different: instances of the database. You should not share a database object between sessions. Each session should get its own database object and therefore its own connection to the database. One app, multiple database objects, multiple connections to the database.

Again: never share a database connection between sessions.

[quote=238645:@Jay Menna]@Norman Palardy Thanks for the help. But your help raises two more questions, so I am afraid I will have to ask for more help.

  1. It appears that Gregs answer is at odds with yours. Explain?
    [/quote]
    Not at all
    Xojo Cloud should be running one instance of the APP - the app can have lots of sessions

[quote=238645:@Jay Menna]
2. You are correct the critical section it throttles my database queries. But since the Plugin is the cause of the crash. and it works around a bug that only Xojo Inc can fix: What would you suggest I do about it? (or am I missing something?)[/quote]
You’re using one connection for the entire app
I’d put the connection on each session that way each session has its own connection & communications wont be interleaved

Going back to the original question, the fact that there are multiple versions of the actual Betty47 app running is mostly an issue of memory. You’ll notice in your logs that they’re all using 0.0% cpu.

Usually this indicates a circular reference somewhere in your app which causes sessions to not shut down properly, and thus cause the app to never quit.

Norman I t look like you and I got lost on the word "instance " Greg and I spent significant running down a very bad issue in my app where multiple instance of THE APPLICATION were being spawned. (Hence the title of the original post)

There is one DB connection for each session. Apologies for the confusion if I implied otherwise.

Greg: We found the problem and fixed it 3 weeks ago. It was the Mysql plugin.