Advertisement
vadimtk

Untitled

Mar 7th, 2011
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.16 KB | None | 0 0
  1. srv_adaptive_flushing_thread(
  2. /*====================*/
  3.         void*   arg __attribute__((unused)))
  4.                         /*!< in: a dummy parameter required by
  5.                         os_thread_create */
  6. {
  7.         uint    auto_lru_dump;
  8.         time_t  last_dump_time;
  9.         time_t  time_elapsed;
  10.  
  11.         ib_uint64_t     lsn_old;
  12.  
  13.         ib_uint64_t     oldest_lsn;
  14.         ib_uint64_t     lsn;
  15.         ib_int64_t     age_gap;
  16.         ulint           n_pages_flushed;
  17.         ulint           n_pend_ios;
  18.         lint            n_flush;
  19.         lint            n_flush_diff;
  20.         lint            n_flush_diff_correction;
  21.         lint            n_flush_time_correction=0; /* n_flush corrected due long flush_batch */
  22.         lint            n_flush_min=100;
  23.         lint            n_flush_max=100000;
  24.         lint            max_velocity = 100000;
  25.         lint            time_correction = 0;
  26.  
  27.         fprintf(stderr, "Apdaptive flushing  thread starts, id %lu\n",
  28.                 os_thread_pf(os_thread_get_curr_id()));
  29.  
  30.  
  31.         last_dump_time = time(NULL);
  32.         n_flush = 100; /*  Initial value to flush pages */
  33.  
  34. loop:
  35.  
  36.         if (time_correction < 100) { /* wait only if we spent less 100ms in previous loop */
  37.                 os_event_wait_time(srv_shutdown_event, 100000-time_correction*1000);
  38.  
  39.                 if (srv_shutdown_state >= SRV_SHUTDOWN_CLEANUP) {
  40.                         goto exit_func;
  41.                 }
  42.         mutex_enter(&(log_sys->mutex));
  43.         oldest_lsn = buf_pool_get_oldest_modification();
  44.         lsn = log_sys->lsn;
  45.         if (!oldest_lsn) oldest_lsn = lsn;
  46.         mutex_exit(&(log_sys->mutex));
  47.  
  48.         // n_pend_ios = buf_get_n_pending_ios();
  49.  
  50.         n_pend_ios = buf_pool->n_flush[BUF_FLUSH_LIST];
  51.  
  52.         age_gap = (log_sys->lsn - oldest_lsn) - ( log_sys->max_modified_age_async - log_sys->max_modified_age_async / 8 );
  53.  
  54.         if (n_pend_ios < 100) {
  55.                 /* calculate how much pages we flush this tact */
  56.                 /* gap= current_age - target_age; */
  57.                 /* Do age correction only if there is no time correction */
  58.                 if (n_flush_time_correction == 0) {
  59.                         n_flush_diff = (lint) age_gap * max_velocity /(ib_int64_t)( log_sys->max_modified_age_async - log_sys->max_modified_age_async / 8 );
  60.                 } else {
  61.                         n_flush_diff = -n_flush_time_correction;
  62.                 }
  63.  
  64.                 /* We do limit increase only to 5% */
  65.  
  66.                 n_flush_diff_correction = n_flush_diff;
  67.  
  68.                 if (n_flush_diff > 0) {
  69.                         n_flush_diff_correction = ut_min(n_flush_diff, n_flush*5/100); /* increase no more than 5% */
  70.                 }
  71.  
  72.                 n_flush += n_flush_diff_correction;
  73.  
  74.                 /* Final n_flush should be in range [n_flush_min, n_flush_max] */
  75.  
  76.                 if (n_flush < n_flush_min) n_flush= n_flush_min;
  77.                 if (n_flush > n_flush_max) n_flush= n_flush_max;
  78.  
  79.  
  80.                 /* Perform batch flush and measure time */
  81.  
  82.  
  83.                 ulint   cur_time = ut_time_ms();
  84.                 n_flush_time_correction = 0;
  85.                 time_correction = 0;
  86.  
  87.                 n_pages_flushed =
  88.                         buf_flush_batch(
  89.                                         BUF_FLUSH_LIST,
  90.                                         n_flush,
  91.                                         IB_ULONGLONG_MAX);
  92.  
  93.                 if (n_pages_flushed == ULINT_UNDEFINED) {
  94.                         n_flush_time_correction = n_flush / 100;
  95.                 }
  96.  
  97.  
  98.                 ulint  exec_time=  ut_time_ms();
  99.  
  100.                 fprintf(stderr,
  101.                                 "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",
  102.                                 (ulong)(lsn - oldest_lsn), age_gap, n_flush_diff, n_flush_diff_correction, n_flush, n_pages_flushed, exec_time-cur_time);
  103.  
  104.                 /* if execution time > 200 ms ( 1 tact ) , we decrease n_flush in next tact */
  105.  
  106.                 if ( (exec_time - cur_time) > 100 ) {
  107.                         n_flush_time_correction = n_flush*( (exec_time - cur_time) / 100 ) / 100;
  108.                 }
  109.                 time_correction = exec_time - cur_time; /* we need to decrease tact time, as some time
  110.                         was spent in buf_flush_batch. if time > 100ms, we skip wait at all */
  111.  
  112.         } else {
  113.                 n_flush = n_flush - n_flush / 100; /* decrease number of pages on 1% */
  114.                 fprintf(stderr,
  115.                         "InnoDB empty tact: age: %lu, pending io: %lld, n_flush_diff: %ld, decr n_flush:%llu\n",
  116.                         (ulong)(lsn - oldest_lsn), n_pend_ios, n_flush / 100, n_flush);
  117.         }
  118.         time_elapsed = time(NULL) - last_dump_time;
  119.                 last_dump_time = time(NULL);
  120.  
  121.         // os_thread_sleep(5000);
  122.  
  123.         goto loop;
  124. exit_func:
  125.         /* We count the number of threads in os_thread_exit(). A created
  126.         thread should always use that to exit and not use return() to exit. */
  127.  
  128.         os_thread_exit(NULL);
  129.  
  130.         OS_THREAD_DUMMY_RETURN;
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement