static tb_void_t tb_demo_spider_exit(tb_demo_spider_t* spider) { // check tb_assert_and_check_return(spider); // trace tb_trace_d("exit: .."); // kill it tb_atomic_set(&spider->state, TB_STATE_KILLING); // kill all transfer tasks tb_transfer_pool_kill_all(tb_transfer_pool()); // kill all parser tasks tb_thread_pool_task_kill_all(tb_thread_pool()); // wait all transfer tasks exiting tb_transfer_pool_wait_all(tb_transfer_pool(), -1); // wait all parser tasks exiting tb_thread_pool_task_wait_all(tb_thread_pool(), -1); // enter tb_spinlock_enter(&spider->lock); // exit filter if (spider->filter) tb_bloom_filter_exit(spider->filter); spider->filter = tb_null; // exit pool if (spider->pool) tb_fixed_pool_exit(spider->pool); spider->pool = tb_null; // leave tb_spinlock_leave(&spider->lock); // exit lock tb_spinlock_exit(&spider->lock); // exit home tb_url_exit(&spider->home); // exit option #ifdef TB_CONFIG_MODULE_HAVE_OBJECT if (spider->option) tb_option_exit(spider->option); spider->option = tb_null; #endif // trace tb_trace_d("exit: ok"); }
static tb_void_t tb_demo_test_cstr_h(tb_size_t index) { // the count tb_size_t count = 1000000; // save func g_func_indx = index; g_func_prev = tb_item_func_str(tb_true); // the func tb_item_func_t func = g_func_prev; func.hash = tb_demo_test_hash_func; // init filter tb_bloom_filter_ref_t filter = tb_bloom_filter_init(TB_BLOOM_FILTER_PROBABILITY_0_001, 1, count, func); if (filter) { // clear random tb_random_clear(tb_random_generator()); // done tb_size_t i = 0; tb_size_t r = 0; tb_char_t s[256] = {0}; tb_hong_t t = tb_mclock(); for (i = 0; i < count; i++) { // the value tb_long_t value = tb_random(); // format it tb_snprintf(s, sizeof(s) - 1, "%ld", value); // set value to filter if (!tb_bloom_filter_set(filter, s)) { // repeat++ r++; } } t = tb_mclock() - t; // trace tb_trace_i("cstr: index: %lu, repeat: %lu, time: %lld ms", index, r, t); // exit filter tb_bloom_filter_exit(filter); } }
static tb_void_t tb_demo_test_uint32_h(tb_size_t index) { // the count tb_size_t count = 1000000; // save func g_func_indx = index; g_func_prev = tb_item_func_uint32(); // the func tb_item_func_t func = g_func_prev; func.hash = tb_demo_test_hash_func; // init filter tb_bloom_filter_ref_t filter = tb_bloom_filter_init(TB_BLOOM_FILTER_PROBABILITY_0_001, 1, count, func); if (filter) { // clear random tb_random_clear(tb_random_generator()); // done tb_size_t i = 0; tb_size_t r = 0; tb_hong_t t = tb_mclock(); for (i = 0; i < count; i++) { // the value tb_long_t value = tb_random_range(tb_random_generator(), 0, TB_MAXU32); // set value to filter if (!tb_bloom_filter_set(filter, (tb_cpointer_t)value)) { // repeat++ r++; } } t = tb_mclock() - t; // trace tb_trace_i("uint32: index: %lu, repeat: %lu, time: %lld ms", index, r, t); // exit filter tb_bloom_filter_exit(filter); } }
static tb_void_t tb_demo_test_cstr_p() { // the count tb_size_t count = 10000000; // init filter tb_bloom_filter_ref_t filter = tb_bloom_filter_init(TB_BLOOM_FILTER_PROBABILITY_0_01, 3, count, tb_item_func_str(tb_true)); if (filter) { // clear random tb_random_clear(tb_random_generator()); // done tb_size_t i = 0; tb_size_t r = 0; tb_char_t s[256] = {0}; for (i = 0; i < count; i++) { // the value tb_long_t value = tb_random(); // format it tb_snprintf(s, sizeof(s) - 1, "%ld", value); // set value to filter if (!tb_bloom_filter_set(filter, s)) { // repeat++ r++; } } // trace #ifdef TB_CONFIG_TYPE_FLOAT tb_trace_i("cstr: count: %lu, repeat: %lu, repeat_p ~= p: %lf", count, r, (tb_double_t)r / count); #else tb_trace_i("cstr: count: %lu, repeat: %lu", count, r); #endif // exit filter tb_bloom_filter_exit(filter); } }