NetTalk Central

NetTalk Web Server => Web Server - Ask For Help => Topic started by: osquiabro on October 17, 2018, 11:49:39 AM

Title: Close All Session and Threads??
Post by: osquiabro on October 17, 2018, 11:49:39 AM
is possible to close all Session and threads via code ?? my app run as services but need one time a day close all without restart a service.
Title: Re: Close All Session and Threads??
Post by: Bruce on October 17, 2018, 10:38:09 PM
go to the WebServer procedures, to source,
You can add code to the start or the
ThisWebServer.StartNewThread
method.

Yoou'll see there's already some code there;
    If (self.performance.NumberOfThreads >= self.MaxThreads and self.MaxThreads > 0) or loc:shuttingDown
      if loc:RequestData.RequestMethodType <> NetWebServer_DELETESESSION and PoolWaiting = 0
        self.SendError(500,'Server Busy','Server Busy, try again shortly')
        self._PerfEndThread(0,0,500)  ! Errors are counted, but otherwise not included in stats
        do UpdateStats
        dispose(p_RequestData.DataString)
      end
      return
    End


You can add your own code just before that to do your own test, and response.
I recommend perhaps a 503 error;

503 Service Unavailable
The server is currently unavailable (because it is overloaded or down for maintenance). Generally, this is a temporary state.[65]

Cheers
Bruce

Title: Re: Close All Session and Threads??
Post by: osquiabro on October 18, 2018, 05:20:24 AM
sorry bruce but don't understand nothing, what function or routine closed a session and threads in this routine?
Title: Re: Close All Session and Threads??
Post by: Bruce on October 18, 2018, 08:08:17 AM
Threads will end themselves as they complete.
Sessions will remain (until they are automatically deleted).

The key is that no new threads will be accepted. So you can set a "quiet time" of maybe a few seconds or whatever to do a backup?

Which I suppose begs the question - WHY do you want to do this?

cheers
Bruce
Title: Re: Close All Session and Threads??
Post by: osquiabro on October 18, 2018, 08:19:08 AM
well, don't why session and threads not closing automatically after user abandon a page.

in performance page i see when nothing is connected to a page the sessions and threads is very high and never closed, so i need to force close all before the site is hanging. My idea is that at midnight all sessions and threads are automatically closed
Title: Re: Close All Session and Threads??
Post by: Bruce on October 18, 2018, 04:17:47 PM
Hi Osa,

you have got completely the wrong approach here.

>> well, don't why session and threads not closing automatically after user abandon a page.

Threads absolutely close - they close long before the user decides to leave the app. If you look at the thread count, that should return to 0 regularly whenever the server is quiet. The typical time for a thread is well less than a second. If your thread count does not return to zero then you are leaking threads - which is a very different problem.

>> after user abandon a page.

the browser does not notify the server when a person leaves your app. It also does not notify you if they close the browser, or just turn off the computer. Thus the server cannot end a session because of that, because it simply does not know when that happens.

What it does do is monitor activity for the session. When a session is inactive for a period of time it is cleaned up. the amount of time is determined by you in the WebServer procedure, Advanced tab. Default value is 15 minutes. Of course if you have reasonably steady traffic then your number of sessions and session data will remain more or less the same.

In short, you are trying to fix a problem that does not exist. I suggest you leave it alone.

cheers
Bruce
Title: Re: Close All Session and Threads??
Post by: osquiabro on October 19, 2018, 05:00:04 AM
hi, bruce the problem exists because when server is quiet not all session and threads is closed, you can see my performance on site in  http://www.crimpr.net:88/performance at midnigth in Puerto Rico time.

>>> Threads absolutely close - they close long before the user decides to leave the app. If you look at the thread count, that should return to 0 regularly whenever the server is quiet. The typical time for a thread is well less than a second. If your thread count does not return to zero then you are leaking threads

how can detect this problem? and my original request is possible to kill all session a threads via code?

Thanks..
Title: Re: Close All Session and Threads??
Post by: Jane on October 19, 2018, 07:14:12 AM
If you really need to do this, you might try

1. Create a new Source procedure called Main.
2. Set Main as your startup procedure.
3. Create a global BYTE variable called CERRAR
4. In Main, have some code like
   CERRAR = 0
   LOOP
      WebServer
      if CERRAR
          BREAK
      END
   END
5. Decide how you're going to determine it's time to do this (timer, some kind of flag, whatever)
6. When it's time, do
      post(event:accepted,?GracefulCloseButton)
      ! That should close the web server.  The loop in MAIN will restart it
7. When you really need to shutdown, set CERRAR = 1
Title: Re: Close All Session and Threads??
Post by: osquiabro on October 19, 2018, 01:30:10 PM
work awesome !!

Thanks Jane..
Title: Re: Close All Session and Threads??
Post by: Bruce on October 21, 2018, 09:13:52 PM
this is _such_ a bad idea....
Title: Re: Close All Session and Threads??
Post by: osquiabro on October 22, 2018, 05:32:44 AM
why? And what is the correct idea or correct procedure?
Title: Re: Close All Session and Threads??
Post by: Bruce on October 26, 2018, 09:31:09 PM
>>  on site in  http://www.crimpr.net:88/performance at midnight

unfortunately I can't access the site from here. Perhaps post a screenshot of what you are seeing.

>> why? And what is the correct idea or correct procedure?

You've not yet demonstrated;
a) that there is a problem at all or
b) that you understand the root cause of the problem or
c) that the proposed solution is useful in any way.

In other words you're treating the (perceived) symptom rather than the actual problem, and it seems to me that your perception of the problem itself may be inaccurate.

cheers
Bruce
Title: Re: Close All Session and Threads??
Post by: osquiabro on October 27, 2018, 10:49:35 AM
the server is down for maintenance, but why is bad idea  the Jane code??,i don't how to identify the problem, but in some occasion the system is hanging, after Jane solutions, the system never hanging again and all threads and connections always return to 0.

Title: Re: Close All Session and Threads??
Post by: bshields on October 28, 2018, 02:11:24 PM
I think what Bruce is saying, is, NetTalk does not require a daily (or periodic) restart.

If it does, it means something is wrong (and usually thats something we've done wrong, not Bruce - in my experience).

Rather than addressing the symptom (just restarting it), you should seek the cause and diagnose it.

At the moment the treatment of the symptom MAY continue to work, but there is something wrong in there somewhere.

Its very likely that if the number of users were to increase you MAY find you need to restart more often than daily, which could become a problem, if you are restarted say every hour.

But, if your system isn't critical or isn't likely to get more users, then maybe your current solution will suffice.

Regards
Bill
Title: Re: Close All Session and Threads??
Post by: DonRidley on October 29, 2018, 02:01:41 AM
I know I'm late to the party but....

I run a NetTalk multi site host server which in turn serves 3 or 4 sites at a time with > 100 users.  It runs 24 hours a day 7 days week, 365 days out of the year.   The NT server has literally ran for months with no restart needed.  The only reason I restart it now is to update one of the site DLL's.

Point being, if you're having to do restarts on a regular basis then something is wrong in your settings, code, etc.  Just my humble opinion.

Don
Title: Re: Close All Session and Threads??
Post by: osquiabro on October 29, 2018, 04:36:33 AM
i know is something is wrong, the site don't need to restart daily but after some days or weeks or inclusive months  the site is hanging, the mayor problem is that don't have a control of server and my app running as services this causes that I can not see what is happening.

Title: Re: Close All Session and Threads??
Post by: bshields on October 29, 2018, 03:36:02 PM
Yeah, fair call. I understand. Its quite a challenge debugging production servers, especially when you cannot reproduce problems in development, made even further difficult by it not being under your hosting control. My systems run lots of "optional" logging so I can diagnose under those circumstances, but it is like trying to turn on a light switch in another room, through a key hole, with pieces a spaghetti, linked together with sticky tape, on a boat, in a storm, while wearing roller skates, and having one hand tied behind your back, after a big night out, nursing a hangover, only to find out the light switch was broken anyway.