-1

In Windows Server 2012 with 2 CPUs I have Apache 2.4 with PHP 5.6 and when I generate a PDF document with DOMPDF a cumulative 50% of total CPU power is used. No matter what I do, I cannot get the total over 50%. I tried opening a bunch of windows and creating a multiple series of PDF docs at the same time.

Each individual CPU will be less than 50% and if one spikes up the other spikes down at the same time. It seems like windows is limiting the Apache service to use 50% of the CPU. Is there somewhere to change this?

Edit: my application is already utilizing both CPUs just not to their full capacity, and after 60 seconds of load, the utilization moves to 100%. I think it is not anything to do with threading... maybe an environment setting?

halfer
  • 19,824
  • 17
  • 99
  • 186
Roofus McDuffle
  • 105
  • 1
  • 10
  • You could set up a RAM disk and see if you can get DOMPDF or PHP to use that as scratch space. As Mark says the process may be disk bound, and if so you'll need to speed the disk up to get more CPU usage. Also, what problem are you trying to solve? Do you want PDFs to be generated faster, or to alleviate the load on your web server? – halfer Jul 09 '15 at 20:07
  • It is using ramdisk already, so I think it is not a disk access problem. Yes the problem I am trying to solve is increasing PDF generation speed. I also did other load tests like looping to produce a load, but something is holding it down to 50%. I was just wondering if this was a setting somewhere in Windows, but if no one has mentioned such a setting yet, perhaps it is not. – Roofus McDuffle Jul 09 '15 at 20:10
  • I don't know the details of how your PDFs generate, but it might be a fair guess that your program is not CPU-bound by definition, since you are only ramping up to 50%. Something else is holding it back - either disk or network. "Thinking" is it is not the disk is not an ideal approach - use xdebug or something else to examine what it is doing. – halfer Jul 09 '15 at 20:28
  • "Yes the problem I am trying to solve is increasing PDF generation speed" - maybe you just need to make PDF creation an offline process? Remove it from your web process, and add it to a worker queue. This has the advantage that a web server process is not locked up for the duration of the generation. Just send a message to your queue to process a PDF, and then tell the user to wait in the next web page. You can use AJAX or WebSockets to periodically retry the server to see if the PDF is ready, and refresh the screen to include a link when it is. – halfer Jul 09 '15 at 20:31
  • The PDF generation only takes 1-2 seconds. But even if I do something like loop a mathematical operation, the CPU still stops at 50%. This uses no disk or network. Here is a picture http://i.imgur.com/mVB0rgg.png – Roofus McDuffle Jul 09 '15 at 20:54
  • Ah gotcha, my misunderstanding. I thought it was not reaching a natural processing limit, but in fact it is: 100% of one CPU. Your code won't be run on more than one CPU at one time, it would need specifically be written to parallelise to do that. However if you get two users generating PDFs at the same time, they will be run in different processes, and hopefully they will be assigned to different CPUs. – halfer Jul 09 '15 at 21:15
  • possible duplicate of [How do you make good use of multicore CPUs in your PHP/MySQL applications?](http://stackoverflow.com/questions/2267345/how-do-you-make-good-use-of-multicore-cpus-in-your-php-mysql-applications) – halfer Jul 09 '15 at 21:15
  • That picture, I should have used a different one. It is using both cores, in that one picture it is using one more than the other, but usually it uses both about 50%. But I just discovered something strange. When I really keep hammering it longer, then it kicks up to 100% CPU usage, but it has to be pegged at 50% for about 60 seconds before that happens... any idea how to change that, so it kicks up to 100% immediately? – Roofus McDuffle Jul 09 '15 at 21:19
  • Could your PDF be created by two processes? If pages are independent of each other, then write separate scripts to create them, and join them at the end. You'll need the queue processor here (e.g. Gearman). That should allocate the two parts to different CPUs. The only objection here is that 1-2 sec is not very long, and it may not be worth the effort involved. – halfer Jul 09 '15 at 21:19
  • Yeah, I don't think it is worth it, but see my comment above, if I load it for 60 seconds or more, the cpu utilization moves to 100% so it makes me think this must be some environment setting. VMware or Windows? Seems a little strange. – Roofus McDuffle Jul 09 '15 at 21:28
  • This is a rather late stage to be declaring that VMWare is in use. I've retagged and modified the title, maybe that will attract new answers. – halfer Jul 09 '15 at 22:26
  • 1
    Sorry, I am dumb :( thank you for editing my question. – Roofus McDuffle Jul 10 '15 at 00:57

1 Answers1

0

It's not windows limitation but program design itself. I think it is related with CPU cores (for example it has 4 cores and uses just 2, literally 50%). As far as I know you cannot do anything about this, as it cannot be split to more cores without proper program design.

Chlorek
  • 138
  • 7
  • It has 2 cores and is using both, but it is not maximizing them. – Roofus McDuffle Jul 09 '15 at 19:48
  • doesn't mean the system isn't busy. if you're building a ton of pdfs, then it's likely that some of that ton of processes is waiting on OTHER things, like disk bandwidth. – Marc B Jul 09 '15 at 19:52
  • So if cpu has 2 cores and it is used in 50% most likely it uses just one. Apache is well multi-threaded as far as I know so it should use all cores. The problem might be a module that is not thread safe, I remember that PHP is such a module, that might be the problem. PHP runs just in one core. #Edit Just found this: http://serverfault.com/questions/310937/setting-up-apache-to-use-multiple-cores – Chlorek Jul 09 '15 at 19:53
  • I am watching the individual cores and I can see they are both being utilized at 20-80% each. These are VMs on fiber channel, so it is probably not disk or network speed. I am using the threadsafe php module. – Roofus McDuffle Jul 09 '15 at 19:56