in reply to Re: Libxml parser cosuming 100% cpu
in thread Libxml parser cosuming 100% cpu

actually i have xml files of 10 lakhs tags. my script take 2.5 min to complete their job.simply i store the files lines into a array and run loop.i give 100 lines to libxml parser so each time parser process 100lines string this job continue untill the loop finish.Now problem is cpu usage which 100% till the job finish.my point is how can i reduce it without sleep command

Replies are listed 'Best First'.
Re^3: Libxml parser cosuming 100% cpu
by ikegami (Patriarch) on Aug 11, 2018 at 13:06 UTC

    You bring up 100% CPU as if it's a bad thing again, but 100% CPU is a good thing. It means no time is being wasted waiting for I/O.

    Think of it this way: Would you rather have an employee that works at 100% of the time they are at work, or 50%?

      Actually there are other task which are getting slower or terminate because of not available of cpu. do you think this is right to be 100% cpu usagre now ?

        I was judging by the criteria that you provided: You wanted the make your program faster. Are you now saying you want to slow down your program to give other programs more CPU time? If so, use nice as previously mentioned.

Re^3: Libxml parser cosuming 100% cpu
by Marshall (Canon) on Aug 12, 2018 at 09:54 UTC
    From your code so far, you read 1 million lines and then use a very inefficient method (lot of CPU and lot of memory) to make a string variable of those lines.

    I don't understand exactly what you mean by 100% CPU? My Windows machine has 4 cores which essentially means 4 CPU's that share a common big memory space.

    Unix is a time sharing O/S. Other processes will get CPU time even if one process is completely compute bound.

    I am not sure about these various XML Perl libs, but every time that your program runs an I/O operation, the O/S scheduler will run. Maybe use something that takes less memory and does more I/O? Every time you do an I/O operation, the O/S scheduler will run.