MXS-1669: Fix load average tracking
The output of `show threads` could have a negative historic thread load average that could be explained by the overflow of the signed 32-bit integer used to count the number of samples. The time that each thread started to process an event for a DCB used an old value that is no longer used. Updating this to DCB::last_read retains the 2.0 behavior.
This commit is contained in:
		@ -125,7 +125,7 @@ SPINLOCK pollqlock = SPINLOCK_INIT;
 | 
				
			|||||||
 * poll completion, a value of 1 or less is the ideal.
 | 
					 * poll completion, a value of 1 or less is the ideal.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
static double load_average = 0.0;
 | 
					static double load_average = 0.0;
 | 
				
			||||||
static int load_samples = 0;
 | 
					static uint64_t load_samples = 0;
 | 
				
			||||||
static int load_nfds = 0;
 | 
					static int load_nfds = 0;
 | 
				
			||||||
static double current_avg = 0.0;
 | 
					static double current_avg = 0.0;
 | 
				
			||||||
static double *avg_samples = NULL;
 | 
					static double *avg_samples = NULL;
 | 
				
			||||||
@ -755,7 +755,7 @@ poll_waitevents(void *arg)
 | 
				
			|||||||
            pollStats.n_fds[(nfds < MAXNFDS ? (nfds - 1) : MAXNFDS - 1)]++;
 | 
					            pollStats.n_fds[(nfds < MAXNFDS ? (nfds - 1) : MAXNFDS - 1)]++;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            load_average = (load_average * load_samples + nfds) / (load_samples + 1);
 | 
					            load_average = (load_average * load_samples + nfds) / (load_samples + 1);
 | 
				
			||||||
            atomic_add(&load_samples, 1);
 | 
					            atomic_add_uint64(&load_samples, 1);
 | 
				
			||||||
            atomic_add(&load_nfds, nfds);
 | 
					            atomic_add(&load_nfds, nfds);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            /*
 | 
					            /*
 | 
				
			||||||
@ -1368,7 +1368,7 @@ dShowThreads(DCB *dcb)
 | 
				
			|||||||
            dcb_printf(dcb,
 | 
					            dcb_printf(dcb,
 | 
				
			||||||
                       " %2d | %-10s | %6d | %-16p | <%3lu00ms | %s\n",
 | 
					                       " %2d | %-10s | %6d | %-16p | <%3lu00ms | %s\n",
 | 
				
			||||||
                       i, state, thread_data[i].n_fds,
 | 
					                       i, state, thread_data[i].n_fds,
 | 
				
			||||||
                       thread_data[i].cur_dcb, 1 + hkheartbeat - dcb->evq.started,
 | 
					                       thread_data[i].cur_dcb, 1 + hkheartbeat - dcb->last_read,
 | 
				
			||||||
                       event_string);
 | 
					                       event_string);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (from_heap)
 | 
					            if (from_heap)
 | 
				
			||||||
@ -1388,8 +1388,8 @@ dShowThreads(DCB *dcb)
 | 
				
			|||||||
static void
 | 
					static void
 | 
				
			||||||
poll_loadav(void *data)
 | 
					poll_loadav(void *data)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    static  int last_samples = 0, last_nfds = 0;
 | 
					    static uint64_t last_samples = 0, last_nfds = 0;
 | 
				
			||||||
    int new_samples, new_nfds;
 | 
					    uint64_t new_samples, new_nfds;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    new_samples = load_samples - last_samples;
 | 
					    new_samples = load_samples - last_samples;
 | 
				
			||||||
    new_nfds = load_nfds - last_nfds;
 | 
					    new_nfds = load_nfds - last_nfds;
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user