SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Keep it simple, stupid! bokehman's Avatar
    Join Date
    Jul 2005
    Posts
    1,935
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Throttle CPU usage!

    From php.ini:
    Code:
    ;;;;;;;;;;;;;;;;;;;
    ; Resource Limits ;
    ;;;;;;;;;;;;;;;;;;;
    
    max_execution_time = 30     ; Maximum execution time of each script, in seconds
    max_input_time = 60	; Maximum amount of time each script may spend parsing request data
    memory_limit = 8M      ; Maximum amount of memory a script may consume (8MB)
    Is there any way to limit CPU usage? I have a script that is doing some very complicated maths and it redlines the CPU for about 15 seconds every time it runs. Is there any way to throttle the CPU usage?

  2. #2
    SitePoint Zealot
    Join Date
    Dec 2005
    Posts
    171
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Depending as to what platform you are one and what is compiled into your PHP version you could look into POSIX threads, W32API, and Process Control Functions. Though I am unsure as to how you would implement this, its just a starting point for you.
    Glass Obelisk - Web Design, Development and Hosting.

  3. #3
    SitePoint Wizard HarryR's Avatar
    Join Date
    Dec 2004
    Location
    London, UK
    Posts
    1,376
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    Suprisingly enough I was researching this last week trying to find a decent solution for one of my Linux servers to throttle CPU usage on a per-user or per-process basis and never really came up with anything useful.

    Generally you'd need administrative rights to implement any of these resource throttling systems. The main one out there seems to be Virtuozzo (a VPS system) which allows you to set guranteed minimum share of the CPU. The Linux virtual server project also allows something similar to this, but I've never used it yet and I'm not sure about how robust it is.

    If you don't mind branching onto Solaris, take a look at Solaris Projects (in conjunction with the fair-share scheduler, and perhaps Zones if you really want to).

    Not sure how much help this is to you, but if you do find a decent solution.. please give me a PM

    Cheers,
    - Harry

    References:
    http://docs.sun.com/app/docs/doc/817...hahuojp?a=view - Overview of Sun's Fair Share scheduler.
    http://www.onlamp.com/pub/a/onlamp/2...4/solaris.html - Controlling Resources with Solaris Projects
    http://www.swsoft.com/en/products/virtuozzo/ - SWSoft's Virtuozzo
    http://linux-vserver.org/ - Linux VServer project


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •