How to optimize the server to use many regular expression operations

My server is slow due to high CPU usage. I tracked the source of using a large number of processors for several reasons:

  • a large number of regular expressions on datasets.
  • strpos, operations substr.
  • Loops through arrays for basic mathematical operations.

All of these operations are necessary for a single search on my website. If the visitor performs a search, the processor switches to 100%. I can do nothing with these operations because they are necessary.

My questions:

  • What would be the best way to configure configuration files such as httpd.conf or php.ini, given that the above operations are the reason for almost all CPU usage?
  • What would be the best way to upgrade the server, given that the above operations are the reason for almost all CPU usage?

UPDATE 1:

Operation example:

preg_match_all('/ValuesBreakdown_\d+_[A-Z]+_out.push\(([\d.,]+)/',$content,$matches);

This single operation does not use much CPU, but it is a large number of such operations that add up.

+3
source share
1 answer

If you experience performance issues, always make sure that the reason is what you think.

First, I recommend using XDebug + webgrind and confirm the reason.

Then you can probably change the logical flow of your code to improve perfs: for example, do you loop your data set several times, and not just once? Are you sure you cannot improve your algorithm? etc..

XDebug, , perf.

0

All Articles