예제 #1
0
function stress_test($category, $client_name, $rate, $total, $msg_per_call, $avg_size)
{
    $send_interval = $msg_per_call / $rate;
    $random = generate_random($avg_size * 2);
    $msgs_since_send = 0;
    $messages = array();
    $last_send_time = microtime(true);
    for ($i = 0; $i < $total; ++$i) {
        $entry = new LogEntry();
        $entry->category = $category;
        $entry->message = make_message($client_name, $avg_size, $i, $random);
        $messages[] = $entry;
        ++$msgs_since_send;
        if ($msgs_since_send >= $msg_per_call) {
            $msgs_since_send = 0;
            scribe_Log_test($messages);
            $messages = array();
            print '.';
            $now = microtime(true);
            $wait = $last_send_time + $send_interval - $now;
            $last_send_time = $now;
            if ($wait > 0) {
                print "going to sleep {$wait} ms\n";
                usleep($wait * 1000000);
            } else {
                print "backed up {$wait} ms\n";
            }
        }
    }
}
예제 #2
0
파일: tests.php 프로젝트: cgvarela/scribe
function stress_test($category, $client_name, $rate, $total, $msg_per_call, $avg_size, $num_categories)
{
    $send_interval = $msg_per_call / $rate;
    $random = generate_random($avg_size * 2);
    $msgs_since_send = 0;
    $messages = array();
    $last_send_time = microtime(true);
    $scribe_client = create_scribe_client();
    for ($i = 0; $i < $total; ++$i) {
        $entry = new LogEntry();
        $entry->category = $category;
        if ($num_categories > 1) {
            $entry->category .= rand(1, $num_categories);
        }
        $entry->message = make_message($client_name, $avg_size, $i, $random);
        $messages[] = $entry;
        ++$msgs_since_send;
        if ($msgs_since_send >= $msg_per_call) {
            $msgs_since_send = 0;
            $ret = scribe_Log_test($messages, $scribe_client);
            $messages = array();
            $now = microtime(true);
            $wait = $last_send_time + $send_interval - $now;
            $last_send_time = $now;
            if ($wait > 0) {
                usleep($wait * 1000000);
            }
        }
    }
}