• Hello,

    I’ve been reading a lot on the forums in regards to CPU load time. Especially: https://www.ads-software.com/support/topic/very-high-cpu-usage?replies=72

    However, the solutions of optimizing the DB, disabling plugins etc. are not helping. Neither are Wp-cache or similar, as I am using W3 Total Cache and Varnish. This is resulting in 3000 req/sec in the frontend.

    My issue is the backend. When I go to settings->permalinks or primarily edit / add new posts, the load time is around 30 secs and CPU load is 100%. I have monitored SQL queries with the plugin SQL mon but all the queries in total are less than 1 sec.

    Therefore I ended up with disabling the function page_rewrite_rules() in wp-includes/rewrite.php. This solved my issue. However, I guess permalinks are not functioning.

    My question is – can I disable the page_rewrite_rules() function and update the permalinks with a custom plugin? E.g. with a crontab every 24 hours.

    WordPress 3.0, PHP5, Apache2, Debian
    +1000 pages (planning on way more
    Permalink structure: /%category%/%postname%
    Hardware: Very powerful virtual machine; 4 CPUs with 2,5Ghz each, 4GB ram, 15000RPM disks etc.

    Thanks for any input.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter rune00

    (@rune00)

    I’ve been debugging a bit and it seems to me that this line will get ALL WordPress pages and re-build the permalinks. Then update the rewrite_rules row in the wp_options table:

    $page_uris = $this->page_uri_index();

    Naturally, when you have thousands of pages it takes forever to rebuild.

    I’m wondering if this could be done more efficient?

    Thread Starter rune00

    (@rune00)

    I have solved this – at least for now. If anyone might be interested here is what I did.

    I looked through the WordPress core code and disabled all calls to the function flush_rules(). It will flush rewrite_rules in the option table and rebuild it from scratch. I don’t want that now, as it is too resource demanding.

    I grep’ed the function and commented out the ones called from backend (when creating, editing or deleting posts (and pages)):

    <homedir>/wp-admin/includes/upgrade.php: // $wp_rewrite->flush_rules();
    <homedir>/wp-admin/includes/upgrade.php: // $wp_rewrite->flush_rules();
    <homedir>/wp-admin/includes/misc.php: // $wp_rewrite->flush_rules();
    <homedir>/wp-admin/includes/schema.php: // $wp_rewrite->flush_rules();
    <homedir>/wp-admin/admin.php: // $wp_rewrite->flush_rules();
    <homedir>/wp-admin/admin.php: // $wp_rewrite->flush_rules(false);
    <homedir>/wp-admin/options-permalink.php:// $wp_rewrite->flush_rules();
    <homedir>/wp-includes/post.php: // $wp_rewrite->flush_rules(false);
    <homedir>/wp-includes/post.php: // $wp_rewrite->flush_rules(false);
    <homedir>/wp-includes/rewrite.php: * @see WP_Rewrite::flush_rules()
    <homedir>/wp-includes/rewrite.php: $wp_rewrite->flush_rules( $hard );
    <homedir>/wp-includes/rewrite.php: function flush_rules($hard = true) {

    I instead sat up an additional webserver that has access to the live database. I created a PHP script to run, whenever needed, that will rebuild rewrite_rules without wasting resources on the live server.

    Problem solved.

    Can you please guide me more to this? I really have a bad problem and the server it’s more down than up.

    I have 200mb db, 45k posts and due to this permalinks the website simply don’t work OK.

    I don’t have problem at backend, i have problems with the website loading in general. The page loads are lik 5 seconds.

    Thank you

    Thread Starter rune00

    (@rune00)

    For the frontend I suggest you use Varnish cache. It will cache every webpage and deliver the content before Apache is activated. Thereby the permalink are cached as well. https://www.varnish-cache.org/

    But this works like WP Super Cache.

    The problem is with the new generated pages…. it kills my server when permalinks are activated.

    Hi guys,

    I have absolutely the same problem – every time when I publish a new page/edit or delete an old one the server (4GB!) crashes. There’s no problem at all if I’m not loged in and I’m not trying to generate a page – the server load is 0.08%. When I hit the publish button it starts to climb and I there’s no other solution but to reboot the server.
    I also have tried disabling plugins, optimizing the database but nothing helps – the problem is persistent and definitely just with the back end.

    If I don’t find a solution I’ll have to drop WP.

    It’s the permalink structure: /%category%/%postname%/

    For performance reasons, it is not a good idea to start your permalink structure with the category, tag, author, or postname fields. The reason is that these are text fields, and using them at the beginning of your permalink structure it takes more time for WordPress to distinguish your Post URLs from Page URLs (which always use the text “page slug” as the URL), and to compensate, WordPress stores a lot of extra information in its database (so much that sites with lots of Pages have experienced difficulties). So, it is best to have at least two path segments in your post’s permalink structure such as /%year%/%post_name%/ or even /posts/%post_name/….

    https://codex.www.ads-software.com/Using_Permalinks#Choosing_your_permalink_structure
    I’ve changed it to %monthnum%/%year%/%category%/%postname%/ and that has solved the problem ??

    Thread Starter rune00

    (@rune00)

    @bpa The problem for you is when publishing the page WordPress re-builds all permalinks as I explained in my previous post.

    You are right. A different permalink structure might solve your problem, but in my case I really needed /%category%/%postname% ??

    Thread Starter rune00

    (@rune00)

    @aaurel1an no WordPress plugin is as effective as a standalone installation of Varnish.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘WordPress CPU load (disable page_rewrite_rules()?)’ is closed to new replies.