WriteLine Taking Too Long?

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
ueberyak
Junior Coder
Posts: 31
Joined: Tue Sep 03, 2013 9:45 pm

WriteLine Taking Too Long?

Post by ueberyak » Mon Jun 01, 2015 8:55 pm

I have a script which retrieves data from a SQL table with the following structure. It then creates a text file for each PO and then uses WriteLine to populate them with the relevant Programs. This was running super fast last week, in 3-5 seconds. This week it can take between 3 and 11 minutes. Looking through the log I see that the script is very quickly getting the SQL data. It looks to me like the hangup is on the WriteLine loop. Is it possible that the text files are being locked and that the script has to wait for them to be unlocked before it can write the next line?

SQL Table Structure

PO Program
123 ABC
123 DEF
123 GHI
456 JKL
456 MNO

123.txt contains
ABC
DEF
GHI

456.txt contains
JKL
MNO

Here's the relevant code:

Code: Select all

//Used to retrieve grouped POs ready for download.
Let>SQL=select PO from dbo.tbl_Tasklist_Export group by PO
DBQuery>dbH,SQL,rsProdOrders,NumRecs,NumFields,0

let>r=0
repeat>r
    let>r=r+1
    let>f=0
    Repeat>f
        let>f=f+1
        Let>this_field=rsProdOrders_%r%_%f%
        //Creates text file for each PO which contains all necessary programs.
        let>SQL2=select Program from dbo.tbl_Tasklist_Export where PO = %this_field%
        
        DBQuery>dbh,SQL2,rsPrograms,NumRecs2,NumFields2,0
            let>r2=0
            repeat>r2
                let>r2=r2+1
                let>f2=0
                Repeat>f2
                    let>f2=f2+1
                    Let>this_field2=rsPrograms_%r2%_%f2%
                    WriteLn>C:\tasklist\%this_field%.tasklist,,%this_field2%
                Until>f2=numfields2
            Until>r2=NumRecs2
    Until>f=numfields
Until>r=numrecs
Thanks,
Josh

ueberyak
Junior Coder
Posts: 31
Joined: Tue Sep 03, 2013 9:45 pm

Re: WriteLine Taking Too Long?

Post by ueberyak » Mon Jun 01, 2015 10:19 pm

I rewrote the script to hold all of the programs for a single PO in a variable, so the WriteLine event only happens once per PO. It ran super fast the first couple of times I ran it but now it's running slow again.

At the start of the job I delete all of the files in C:\tasklist\. I verified that all of the files are being deleted, but is it possible that there is some sort of conflict happening in the background anyway?

Code: Select all

DeleteFile>C:\tasklist\*.tasklist
Thanks,
Josh

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: WriteLine Taking Too Long?

Post by Marcus Tettmar » Tue Jun 02, 2015 10:33 am

WriteLn should be pretty quick, I'm not sure why it would sometimes slow down. Is there something else running on the system which is interrogating that file - maybe a virus checker or similar? Maybe it is noticing a change and scanning it? Try temporarily disabling security software and see if that makes a difference.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

ueberyak
Junior Coder
Posts: 31
Joined: Tue Sep 03, 2013 9:45 pm

Re: WriteLine Taking Too Long?

Post by ueberyak » Tue Jun 02, 2015 6:27 pm

Ugh, it looks like you're right (I can't be sure, though, because our endpoint protection is so robust that I can't seem to disable it to test.). I realized that the times when the job ran quickly were when I manually kicked off the job. It looks like when the job gets scheduled, the files get interrogated.
Thanks,
Josh

ueberyak
Junior Coder
Posts: 31
Joined: Tue Sep 03, 2013 9:45 pm

Re: WriteLine Taking Too Long?

Post by ueberyak » Tue Jun 02, 2015 9:51 pm

Update: I started using My Documents instead of C:\ and things seem to be running properly without any interference from my antivirus.
Thanks,
Josh

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts