コード例 #1
0
ファイル: clean_worker.hpp プロジェクト: 0x3FFFFFFF/tair
void CleanWorker::start() {
    client_helper.set_timeout(5000);
    bool done = client_helper.startup(_server_addr, NULL, _group_name);
    if (done == false) {
        fprintf(stderr, "file %s, line %d: %s cann't connect.\n",
                __FILE__, __LINE__, _server_addr);
        return;
    }
    int flag = pthread_create(&_work_thread, NULL, thread_func, this);
    if (flag < 0) {
        fprintf(stderr, "file %s, line %d: %s\n",
                __FILE__, __LINE__, strerror(errno));
        return;
    }
}
コード例 #2
0
int main(int argc, const char *argv[])
{
    if (argc < 3) {
        log_error("Usage %s thread_number task_per_number", argv[0]);
        return EXIT_FAILURE;
    }
    int thread_number = atoi(argv[1]);
    int task_per_thread = atoi(argv[2]);

    TBSYS_LOGGER.setLogLevel("INFO");
    bool done = tairClient.startup("10.138.87.53", "10.138.87.54", "group_1");


    int rc = tairClient.remove_area(10);
    if (0 != rc) {
        log_error("remove area 10 failed, rc:%d", rc);
        return EXIT_FAILURE;
    }

    struct timeval begin_time;
    struct timeval end_time;
    gettimeofday(&begin_time, NULL);

    std::vector<boost::thread*> thread_vec;
    for (int i = 0; i < thread_number; i++) {
        boost::thread* thrd = new boost::thread(boost::bind(&zadd_data, i, task_per_thread));
        thread_vec.push_back(thrd);
    }   

    std::vector<boost::thread*>::iterator it = thread_vec.begin();
    for(; it != thread_vec.end(); ++it) {
        (*it)->join();
    }   

    gettimeofday(&end_time, NULL);
    log_info("used time:%ld success:%d failed:%d\n", diff_time(begin_time, end_time), success, failed);
    return 0;
}