Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- srv_adaptive_flushing_thread(
- /*====================*/
- void* arg __attribute__((unused)))
- /*!< in: a dummy parameter required by
- os_thread_create */
- {
- uint auto_lru_dump;
- time_t last_dump_time;
- time_t time_elapsed;
- ib_uint64_t lsn_old;
- ib_uint64_t oldest_lsn;
- ib_uint64_t lsn;
- ib_int64_t age_gap;
- ulint n_pages_flushed;
- ulint n_pend_ios;
- lint n_flush;
- lint n_flush_diff;
- lint n_flush_diff_correction;
- lint n_flush_time_correction=0; /* n_flush corrected due long flush_batch */
- lint n_flush_min=100;
- lint n_flush_max=100000;
- lint max_velocity = 100000;
- lint time_correction = 0;
- fprintf(stderr, "Apdaptive flushing thread starts, id %lu\n",
- os_thread_pf(os_thread_get_curr_id()));
- last_dump_time = time(NULL);
- n_flush = 100; /* Initial value to flush pages */
- loop:
- if (time_correction < 100) { /* wait only if we spent less 100ms in previous loop */
- os_event_wait_time(srv_shutdown_event, 100000-time_correction*1000);
- if (srv_shutdown_state >= SRV_SHUTDOWN_CLEANUP) {
- goto exit_func;
- }
- mutex_enter(&(log_sys->mutex));
- oldest_lsn = buf_pool_get_oldest_modification();
- lsn = log_sys->lsn;
- if (!oldest_lsn) oldest_lsn = lsn;
- mutex_exit(&(log_sys->mutex));
- // n_pend_ios = buf_get_n_pending_ios();
- n_pend_ios = buf_pool->n_flush[BUF_FLUSH_LIST];
- age_gap = (log_sys->lsn - oldest_lsn) - ( log_sys->max_modified_age_async - log_sys->max_modified_age_async / 8 );
- if (n_pend_ios < 100) {
- /* calculate how much pages we flush this tact */
- /* gap= current_age - target_age; */
- /* Do age correction only if there is no time correction */
- if (n_flush_time_correction == 0) {
- n_flush_diff = (lint) age_gap * max_velocity /(ib_int64_t)( log_sys->max_modified_age_async - log_sys->max_modified_age_async / 8 );
- } else {
- n_flush_diff = -n_flush_time_correction;
- }
- /* We do limit increase only to 5% */
- n_flush_diff_correction = n_flush_diff;
- if (n_flush_diff > 0) {
- n_flush_diff_correction = ut_min(n_flush_diff, n_flush*5/100); /* increase no more than 5% */
- }
- n_flush += n_flush_diff_correction;
- /* Final n_flush should be in range [n_flush_min, n_flush_max] */
- if (n_flush < n_flush_min) n_flush= n_flush_min;
- if (n_flush > n_flush_max) n_flush= n_flush_max;
- /* Perform batch flush and measure time */
- ulint cur_time = ut_time_ms();
- n_flush_time_correction = 0;
- time_correction = 0;
- n_pages_flushed =
- buf_flush_batch(
- BUF_FLUSH_LIST,
- n_flush,
- IB_ULONGLONG_MAX);
- if (n_pages_flushed == ULINT_UNDEFINED) {
- n_flush_time_correction = n_flush / 100;
- }
- ulint exec_time= ut_time_ms();
- fprintf(stderr,
- "InnoDB flush: age: %lu, age_gap: %lld, n_flush_diff: %ld, n_flush_diff_corr: %ld, n_flush: %llu, flushed: %llu, time ms: %llu\n",
- (ulong)(lsn - oldest_lsn), age_gap, n_flush_diff, n_flush_diff_correction, n_flush, n_pages_flushed, exec_time-cur_time);
- /* if execution time > 200 ms ( 1 tact ) , we decrease n_flush in next tact */
- if ( (exec_time - cur_time) > 100 ) {
- n_flush_time_correction = n_flush*( (exec_time - cur_time) / 100 ) / 100;
- }
- time_correction = exec_time - cur_time; /* we need to decrease tact time, as some time
- was spent in buf_flush_batch. if time > 100ms, we skip wait at all */
- } else {
- n_flush = n_flush - n_flush / 100; /* decrease number of pages on 1% */
- fprintf(stderr,
- "InnoDB empty tact: age: %lu, pending io: %lld, n_flush_diff: %ld, decr n_flush:%llu\n",
- (ulong)(lsn - oldest_lsn), n_pend_ios, n_flush / 100, n_flush);
- }
- time_elapsed = time(NULL) - last_dump_time;
- last_dump_time = time(NULL);
- // os_thread_sleep(5000);
- goto loop;
- exit_func:
- /* We count the number of threads in os_thread_exit(). A created
- thread should always use that to exit and not use return() to exit. */
- os_thread_exit(NULL);
- OS_THREAD_DUMMY_RETURN;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement