NetTalk Central

NetTalk Web Server => Web Server - Ask For Help => Topic started by: Djordje Radovanovic on November 18, 2014, 07:12:36 AM

Title: Best practice
Post by: Djordje Radovanovic on November 18, 2014, 07:12:36 AM
I am looking for a best way to do some coding.

I have server which receives during day a lot of information from various devices. At the end of the day I need to forward cumulative data from every device to main server (data integrator). Cause I have lot of devices, I assume that the best way to do that is when data flow is lowest during the day (about 3-4 am). Data flow still exists so I can not block my server with long batch process and I tried to implement some kind of pulling mechanism to send all reports one by one.
I make timer interrupt  on webserver window and every few seconds this code is in process:

    OF EVENT:Timer
        if CurrentDate < Today() and SET:TIMEFORAUDIT < Clock()
          x# = Window{PROP:Timer}
          Window{PROP:Timer} = 0
          Do GetLOGFile
          CurrentDate = Today()
          Window{PROP:Timer} = x#
        END
        ToLog = Records(SDCLoging)
        if ToLog > 0
          NumLogs += 1
          x# = Window{PROP:Timer}
          Window{PROP:Timer} = 0
          set(LOG:SortKey)
          if Access:SDCLoging.Next() = LEVEL:Benign
            resume(Start(ProcessAudit,15000,LOG:Device))   
            Access:SDCLoging.DeleteRecord(0)
          END
          Window{PROP:Timer} = 200
        ELSE
          Window{PROP:Timer} = 6000
        END

Does this code have some implication on server stability and if it does, how to implement this option?

Best regards,

Djordje Radovanovic

Title: Re: Best practice
Post by: MyBrainIsFull on November 18, 2014, 01:17:55 PM
Hi, whenever I need to do background work I make a slave exe to do the dirty work
This will run leaving the server to do its thing, you can hard code it or pass it paramaters

 of timer
   if time = 3am
     RUN( ' slave.exe  param1  param2 ' )

I have used this for the past 10 years and it works fine
Hope this helps
K
Title: Re: Best practice
Post by: Bruce on November 18, 2014, 09:42:23 PM
Hi Djordje,

Kevin's approach is not a bad one - although starting a new exe can be tricky if you don't get all the permissions right.

I would probably do something similar to what you are doing, but I would have a separate thread do all the house-keeping.

In other words, after the web server has started up - say after 30 seconds or so, trigger

HouseKeepingThread = Start(HouseKeeping,25000)

That can be it's own window with a timer, and do all the things it needs to do. You can add as much code in there as you like, but the risk of interfering with the server is very low.

Only extra thing you need to add is the ability to POST a close:Window to that thread when the parent (ie web server program) wants to close. Otherwise the Exe will not close completely.

Cheers
Bruce
Title: Re: Best practice
Post by: Djordje Radovanovic on November 18, 2014, 11:13:31 PM
Thanks Kevin and Bruce.
My perception of threading obviously was wrong. I was starting new thread every now and than. Bruce method with one active thread during program execution is much more appropriate.

Best regards,

Djordje Radovanovic