NetTalk Central

Author Topic: Close All Session and Threads??  (Read 5064 times)

osquiabro

  • Hero Member
  • *****
  • Posts: 664
    • View Profile
    • Email
Close All Session and Threads??
« 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.

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11155
    • View Profile
Re: Close All Session and Threads??
« Reply #1 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


osquiabro

  • Hero Member
  • *****
  • Posts: 664
    • View Profile
    • Email
Re: Close All Session and Threads??
« Reply #2 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?

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11155
    • View Profile
Re: Close All Session and Threads??
« Reply #3 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

osquiabro

  • Hero Member
  • *****
  • Posts: 664
    • View Profile
    • Email
Re: Close All Session and Threads??
« Reply #4 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

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11155
    • View Profile
Re: Close All Session and Threads??
« Reply #5 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

osquiabro

  • Hero Member
  • *****
  • Posts: 664
    • View Profile
    • Email
Re: Close All Session and Threads??
« Reply #6 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..

Jane

  • Sr. Member
  • ****
  • Posts: 347
  • Expert on nothing with opinions on everything.
    • View Profile
    • Email
Re: Close All Session and Threads??
« Reply #7 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

osquiabro

  • Hero Member
  • *****
  • Posts: 664
    • View Profile
    • Email
Re: Close All Session and Threads??
« Reply #8 on: October 19, 2018, 01:30:10 PM »
work awesome !!

Thanks Jane..

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11155
    • View Profile
Re: Close All Session and Threads??
« Reply #9 on: October 21, 2018, 09:13:52 PM »
this is _such_ a bad idea....

osquiabro

  • Hero Member
  • *****
  • Posts: 664
    • View Profile
    • Email
Re: Close All Session and Threads??
« Reply #10 on: October 22, 2018, 05:32:44 AM »
why? And what is the correct idea or correct procedure?

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11155
    • View Profile
Re: Close All Session and Threads??
« Reply #11 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

osquiabro

  • Hero Member
  • *****
  • Posts: 664
    • View Profile
    • Email
Re: Close All Session and Threads??
« Reply #12 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.


bshields

  • Sr. Member
  • ****
  • Posts: 392
    • View Profile
    • Inhabit
    • Email
Re: Close All Session and Threads??
« Reply #13 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

DonRidley

  • Don Ridley
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 729
  • donaldridley2011@gmail.com
    • View Profile
    • Email
Re: Close All Session and Threads??
« Reply #14 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
"Eliminate the impossible, whatever remains, however unlikely, must be the truth."

NetTalk 12.55
Clarion 11