upper bound on the number of sessions in a shared process

Added by Stoycho Stefanov 3 months ago

Hi everybody,

I need to limit the number of sessions which can be started within the WServer. As far as I understand, the parameter <max-num-sessions> in "wt_config.xml" make sense only when I use <dedicated-process> and has no effect in a <shared-process> mode. Am I right and if so, how could I accomplish this task by myself, or I'm doing something wrong?

Thanks in advance for your help!

Best regards
Stoycho


Replies

RE: upper bound on the number of sessions in a shared process - Added by Koen Deforche 3 months ago

Hey,

Wt indeed does not provide what you want. You could track this yourself by tracking the number of application constructors and destructors ?

Regards,
koen

RE: upper bound on the number of sessions in a shared process - Added by Stoycho Stefanov 3 months ago

Hi,

I expected this answer.

Thanks anyway!

regards,
Stoycho

RE: upper bound on the number of sessions in a shared process - Added by Stoycho Stefanov 3 months ago

Hi again,

how could I send a standard http status message when the maximum sessions number is reached. For now I'm instantiating a new WApplication, redirect it to a local error.html file and quit it (as shown in the example in the WApplication reference), but doing so the user cannot go back and request a new session by, for example, browser back or refresh button click and he/she have to write the homepage address again.

Regards,
Stoycho

RE: upper bound on the number of sessions in a shared process - Added by Koen Deforche 2 months ago

Hey,

You could also render a page e.g. using WText or WTemplate, and quit() ? In that way the URL does not change and a user could reload().

Regards,
koen

RE: upper bound on the number of sessions in a shared process - Added by Stoycho Stefanov 2 months ago

Hey,

I had already tried that, but it doesn't work. Here is my code:

if (WebApp::sessionCnt>2)
{
    std::cout << std::endl << MSGAT << "sessionCnt = "<<WebApp::sessionCnt << std::endl << std::endl;
    app= new Wt::WApplication(env);
    app->root()->addWidget(new Wt::WText("503"));
    app->quit();
}

It seems, that after session's quit a new one is created automatically and quit again (session number still equal to the upper bound) and so on until some other session is destroyed and the counter decreases below the threshold. Here the output:
[2012-Mar-09 17:13:36.801744] 2602 [/ Qojno48D4KaZ4I2w] [notice] "Session created (#sessions = 3)" 
[2012-Mar-09 17:13:36.812273] 2602 [/ Qojno48D4KaZ4I2w] [notice] "UserAgent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20100101 Firefox/10.0.2" 

..\scr\Main.cpp:37: sessionCnt = 2

[2012-Mar-09 17:13:36.931048] 2602 [/ Qojno48D4KaZ4I2w] [notice] "Session destroyed (#sessions = 2)" 
[2012-Mar-09 17:13:36.993669] "GET /?wtd=EtZmciJwb0j7UdBd&sid=2920886830 HTTP/1.1" 200 2442
[2012-Mar-09 17:13:37.070177] 2602 [/ Ze99p0DtfoBAlsWb] [notice] "Session created (#sessions = 3)" 
[2012-Mar-09 17:13:37.079943] 2602 [/ Ze99p0DtfoBAlsWb] [notice] "UserAgent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20100101 Firefox/10.0.2" 

..\scr\Main.cpp:37: sessionCnt = 2

[2012-Mar-09 17:13:37.250048] "GET /?wtd=Qojno48D4KaZ4I2w&sid=60377964 HTTP/1.1" 200 2444
[2012-Mar-09 17:13:37.260699] 2602 [/ Ze99p0DtfoBAlsWb] [notice] "Session destroyed (#sessions = 2)" 
[2012-Mar-09 17:13:37.324359] 2602 [/ MU1bjE1vvmQR9rXK] [notice] "Session created (#sessions = 3)" 

regards
Stoycho

RE: upper bound on the number of sessions in a shared process - Added by Pieter Libin 2 months ago

Hey,

I tried to reproduce this behaviour with the attached example (hello.C),
however, no session was created after quitting the application.

If you have a way to change the example to reproduce the problem,
please let us know.

This is the output my test case generated:

[2012-Mar-14 16:28:08.549021] 4699 - [info] "config: reading Wt config file: /etc/wt/wt_config.xml (location = '../../build/examples/hello/hello.wt')" 
[2012-Mar-14 16:28:08.551122] 4699 - [info] "wthttp: reading wthttpd configuration from: /etc/wt/wthttpd" 
[2012-Mar-14 16:28:08.551420] 4699 - [info] "WServer/wthttp: initializing built-in wthttpd" 
[2012-Mar-14 16:28:08.552273] 4699 - [info] "wthttp: started server: http://0.0.0.0:8080" 
[2012-Mar-14 16:28:10.237865] 4699 - [info] "Wt: session created (#sessions = 1)" 
[2012-Mar-14 16:28:10.238504] 4699 [/ jNx9EcZ2qqpi1vKT] [info] "WEnvironment: UserAgent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.33 Safari/535.19" 
127.0.0.1 - - [2012-Mar-14 16:28:10.241517] "GET /?_=/form-widgets/wtextedit HTTP/1.1" 200 2367
[2012-Mar-14 16:28:10.241693] 4699 - [info] "WebRequest: took 4.297ms" 
127.0.0.1 - - [2012-Mar-14 16:28:10.254898] "GET /?wtd=jNx9EcZ2qqpi1vKT&request=style HTTP/1.1" 200 92
[2012-Mar-14 16:28:10.255035] 4699 - [info] "WebRequest: took 5.934ms" 
[2012-Mar-14 16:28:10.259728] 4699 [/ jNx9EcZ2qqpi1vKT] [info] "Wt: session destroyed (#sessions = 0)" 
127.0.0.1 - - [2012-Mar-14 16:28:10.263206] "GET /resources//themes/default/wt.css HTTP/1.1" 304 0
127.0.0.1 - - [2012-Mar-14 16:28:10.263556] "GET /resources/webkit-transitions.css HTTP/1.1" 304 0
127.0.0.1 - - [2012-Mar-14 16:28:10.268492] "GET /?wtd=jNx9EcZ2qqpi1vKT&sid=2315015349&htmlHistory=true&deployPath=%2F&request=script&rand=2982285030 HTTP/1.1" 200 39438
[2012-Mar-14 16:28:10.268686] 4699 - [info] "WebRequest: took 17.254ms" 
127.0.0.1 - - [2012-Mar-14 16:28:10.322807] "GET /favicon.ico HTTP/1.1" 404 85

kind regards,

Pieter

hello.C - hello.C (652 Bytes)

RE: upper bound on the number of sessions in a shared process - Added by Stoycho Stefanov 2 months ago

Hi Pieter,

I tried your example and can report two things.

1. I'm not sure that your code when compiled within my project works fine. I get this output:

[2012-Mar-14 17:55:31.566812] 2347 - [notice] "Wt: initializing built-in httpd" 
[2012-Mar-14 17:55:31.573496] 2347 - [notice] "Reading Wt config file: ./wt_config.xml (location = './halloWt.wt')" 
[2012-Mar-14 17:55:31.620554] 2347 - [notice] "Started server: http://0.0.0.0:80" 
[2012-Mar-14 17:55:34.253003] 2347 [/ IjCxqCFFQtaInvLn] [notice] "Session created (#sessions = 1)" 
[2012-Mar-14 17:55:34.265424] 2347 [/ IjCxqCFFQtaInvLn] [notice] "UserAgent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20100101 Firefox/10.0.2" 
[2012-Mar-14 17:55:34.357160] 2347 [/ IjCxqCFFQtaInvLn] [fatal] "Could not start application." 
10.0.2.80 - - [2012-Mar-14 17:55:34.371105] "GET /?wtd=emi3rS1ozT8jrMal&sid=1162147711 HTTP/1.1" 500 81
[2012-Mar-14 17:55:34.377301] 2347 [/ IjCxqCFFQtaInvLn] [notice] "Session destroyed (#sessions = 0)" 

the bowser shows "Error occurred: Could not start application.", which corresponds to the [fatal] error message from the server. There is something confusing for me in this example, namely, there is no "return" in "createApplication".

2. yes, the problem can be reproduced by letting "createApplication" to return the "app", which is already quit and that seems to cause the problem. I tried to return a null pointer instead, but I still get the fatal error: "Error occurred: Could not start application." When the session number decreases below the threshold and a new session is started by pressing the refresh button (or F5), what is actually my goal, but I cannot define by myself the error message shown.

Here is my full code (main.cpp).

Regards,

Stoycho

main.cpp (1.5 KB)

RE: upper bound on the number of sessions in a shared process - Added by Koen Deforche 2 months ago

Hey stoycho,

What version of wt is this?

Koen

RE: upper bound on the number of sessions in a shared process - Added by Stoycho Stefanov 2 months ago

Hey Koen,

I beg your pardon! I forgot to mention it. It is Wt-3.1.11. I don't want to waste your time answering questions referred to old Wt versions, but I have to.

Regards,
Stoycho

RE: upper bound on the number of sessions in a shared process - Added by Pieter Libin 2 months ago

Hey,

I tried to reproduce your test case with wt 3.1.11, however,
I got some compile problems, so I fixed them and also added a return statement for app, in stead of returning 0, you can find the test case I used attached to this message.

But even with the test case, and in combination with wt3.1.11, I was not able to reproduce the problem.

This is the output I saw:

[2012-Mar-15 15:34:38.263892] 25885 - [notice] "Wt: initializing built-in httpd" 
[2012-Mar-15 15:34:38.264080] 25885 - [notice] "Reading Wt config file: /etc/wt/wt_config.xml (location = 'WebApp')" 
[2012-Mar-15 15:34:38.265267] 25885 - [notice] "Reading wthttpd configuration from: /etc/wt/wthttpd" 
[2012-Mar-15 15:34:38.265829] 25885 - [notice] "Started server: http://0.0.0.0:8080" 
[2012-Mar-15 15:34:41.836617] 25885 [/ fnvYkWIPwdk6Jkg8] [notice] "Session created (#sessions = 1)" 
[2012-Mar-15 15:34:41.836879] 25885 [/ fnvYkWIPwdk6Jkg8] [notice] "UserAgent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.33 Safari/535.19" 
127.0.0.1 - - [2012-Mar-15 15:34:41.837904] "GET / HTTP/1.1" 200 1743
127.0.0.1 - - [2012-Mar-15 15:34:41.847909] "GET /?wtd=fnvYkWIPwdk6Jkg8&request=style HTTP/1.1" 200 91
127.0.0.1 - - [2012-Mar-15 15:34:41.850282] "GET /resources//themes/default/wt.css HTTP/1.1" 404 85
127.0.0.1 - - [2012-Mar-15 15:34:41.850353] "GET /resources/webkit-transitions.css HTTP/1.1" 404 85
127.0.0.1 - - [2012-Mar-15 15:34:41.855857] "GET /?wtd=fnvYkWIPwdk6Jkg8&sid=3359427997&htmlHistory=true&request=script&rand=3837667072 HTTP/1.1" 200 33155
127.0.0.1 - - [2012-Mar-15 15:34:41.900575] "GET /images/favicon.ico HTTP/1.1" 404 85
127.0.0.1 - - [2012-Mar-15 15:34:41.955406] "POST /?wtd=fnvYkWIPwdk6Jkg8 HTTP/1.1" 200 50
[2012-Mar-15 15:34:46.907210] 25885 [/ qso9Gs7LqNToR6Cc] [notice] "Session created (#sessions = 2)" 
[2012-Mar-15 15:34:46.907389] 25885 [/ qso9Gs7LqNToR6Cc] [notice] "UserAgent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.33 Safari/535.19" 
127.0.0.1 - - [2012-Mar-15 15:34:46.908142] "GET / HTTP/1.1" 200 1739
127.0.0.1 - - [2012-Mar-15 15:34:46.919014] "GET /?wtd=qso9Gs7LqNToR6Cc&request=style HTTP/1.1" 200 91
[2012-Mar-15 15:34:46.920362] 25885 [/ qso9Gs7LqNToR6Cc] [notice] "Session destroyed (#sessions = 1)" 
127.0.0.1 - - [2012-Mar-15 15:34:46.921002] "GET /resources//themes/default/wt.css HTTP/1.1" 404 85
127.0.0.1 - - [2012-Mar-15 15:34:46.921102] "GET /resources/webkit-transitions.css HTTP/1.1" 404 85
127.0.0.1 - - [2012-Mar-15 15:34:46.926761] "GET /?wtd=qso9Gs7LqNToR6Cc&sid=162587301&htmlHistory=true&request=script&rand=3323939432 HTTP/1.1" 200 33154
127.0.0.1 - - [2012-Mar-15 15:34:46.974751] "GET /images/favicon.ico HTTP/1.1" 404 85

Pieter

hello.C (1.8 KB)