Changeset 3872

Show
Ignore:
Timestamp:
08/20/10 14:12:55 (1 year ago)
Author:
janl
Message:

* munin-html: Start using fork to save some wall-clock time. Option --fork us now active and max_html_jobs is recognized by munin-html as the maximum number of paralell processes.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.4-stable/common/lib/Munin/Common/Config.pm

    r3594 r3872  
    3838        "onlynullcdef", "group_order", "pipe", "pipe_command", 
    3939        "unknown_limit", "num_unknowns", "dropdownlimit", 
    40         "max_graph_jobs", "max_cgi_graph_jobs", "munin_cgi_graph_jobs" ); 
     40        "max_graph_jobs", "max_cgi_graph_jobs", "munin_cgi_graph_jobs", 
     41        "max_html_jobs", ); 
    4142 
    4243my %bools = map { $_ => 1} qw(yes no true false on off 1 0); 
  • branches/1.4-stable/master/lib/Munin/Master/HTMLOld.pm

    r3302 r3872  
    9090 
    9191my $do_dump = 0; 
    92 my $do_fork = 0; # No effect in this program. 
     92my $do_fork = 1; 
     93my $max_running=6; 
     94my $running=0; 
     95 
    9396 
    9497sub html_startup { 
     
    123126    $htmldir = $config->{htmldir}; 
    124127 
     128    $max_running = &munin_get($config, "max_html_jobs", $max_running); 
     129 
    125130    %comparisontemplates = instanciate_comparison_templates($tmpldir); 
    126131 
     
    163168    my $groups = get_group_tree($config); 
    164169 
    165      
    166  
    167170    if (!defined($groups) or scalar(%{$groups} eq '0')) { 
    168171        LOGCROAK "[FATAL] There is nothing to do here, since there are no nodes with any plugins.  Please refer to http://munin-monitoring.org/wiki/FAQ_no_graphs"; 
    169172    }; 
    170173         
    171  
    172174    if (defined $groups->{"name"} and $groups->{"name"} eq "root") { 
    173175        $groups = $groups->{"groups"};    # root->groups 
     
    181183        exit 0; 
    182184    } 
    183  
    184      
    185185 
    186186    generate_group_templates($groups); 
     
    824824 
    825825 
     826sub fork_and_work { 
     827    my ($work) = @_; 
     828 
     829    if (!$do_fork) { 
     830 
     831        # We're not forking.  Do work and return. 
     832        DEBUG "[DEBUG] Doing work synchrnonously"; 
     833        &$work; 
     834        return; 
     835    } 
     836 
     837    # Make sure we don't fork too much 
     838    while ($running >= $max_running) { 
     839        DEBUG 
     840            "[DEBUG] Too many forks ($running/$max_running), wait for something to get done"; 
     841        look_for_child("block"); 
     842        --$running; 
     843    } 
     844 
     845    my $pid = fork(); 
     846 
     847    if (!defined $pid) { 
     848        ERROR "[ERROR] fork failed: $!"; 
     849        die "fork failed: $!"; 
     850    } 
     851 
     852    if ($pid == 0) { 
     853 
     854        # This block does the real work.  Since we're forking exit 
     855        # afterwards. 
     856 
     857        &$work; 
     858 
     859        # See?! 
     860 
     861        exit 0; 
     862 
     863    } 
     864    else { 
     865        ++$running; 
     866        DEBUG "[DEBUG] Forked: $pid. Now running $running/$max_running"; 
     867        while ($running and look_for_child()) { 
     868            --$running; 
     869        } 
     870    } 
     871} 
     872 
     873 
    826874sub generate_group_templates { 
    827875    my $arr = shift || return; 
     
    837885            if (defined $key->{'ngroups'} and $key->{'ngroups'}) { 
    838886                # WTF: $key->{'groups'} = $key->{'groups'}; 
    839                 generate_group_templates($key->{'groups'}); 
     887                fork_and_work(sub {generate_group_templates($key->{'groups'})}); 
    840888 
    841889                emit_group_template($key);