public void autoTune ( Long progress ) { // LOG.info ("Called auto tune with progress " + progress); if ( lastAction == ACTION . NOOP ) { // We did not take any action last time if ( prevProgress == - 1 ) { // The first time around when we are called doAction ( ACTION . INCREASE , autoTuneFactor , progress ) ; } else if ( moreThanNum ( progress , prevProgress , progressBound ) ) { // We have seen a sudden increase in progress in the steady state (NOOP) try to push // the max spout pending limit even more doAction ( ACTION . INCREASE , autoTuneFactor , progress ) ; } else if ( lessThanNum ( progress , prevProgress , progressBound ) ) { // We have seen a sudden drop in progress in the steady state try to decrease // the max spout pending proportionately to see if we can introduce an improvement // in progress; doAction ( ACTION . DECREASE , Math . max ( ( prevProgress - progress ) / ( float ) prevProgress , autoTuneFactor ) , progress ) ; } else { ++ callsInNoop ; // If the progress remains the same then once in a while try increasing the // max spout pending. if ( callsInNoop >= NOOP_THRESHOLD ) { doAction ( speculativeAction , autoTuneFactor , progress ) ; speculativeAction = speculativeAction == ACTION . INCREASE ? ACTION . DECREASE : ACTION . INCREASE ; } } } else if ( lastAction == ACTION . INCREASE ) { if ( moreThanNum ( progress , prevProgress , autoTuneFactor - progressBound ) ) { // Our increase last time did result in a commisurate increase. Increase even more doAction ( ACTION . INCREASE , autoTuneFactor , progress ) ; } else if ( lessThanNum ( progress , prevProgress , progressBound ) ) { // Our increase last time actually resulted in a decrease. // Check how much we decreased. If our decrease was disproportionate // decrease accordingly. float drop = Math . max ( ( prevProgress - progress ) / ( float ) prevProgress , autoTuneFactor ) ; if ( drop > autoTuneFactor ) { doAction ( ACTION . DECREASE , drop , progress ) ; } else { doAction ( ACTION . RESTORE , autoTuneFactor , progress ) ; } } else { // Our increase last time did not really change anything. So restore. doAction ( ACTION . RESTORE , autoTuneFactor , progress ) ; } } else if ( lastAction == ACTION . DECREASE ) { if ( moreThanNum ( progress , prevProgress , progressBound ) ) { // We actually saw an increase in progress. So decrease more doAction ( ACTION . DECREASE , autoTuneFactor , progress ) ; } else { // Hold off any decision. We will take any decision next time around. doAction ( ACTION . NOOP , autoTuneFactor , progress ) ; } } else if ( lastAction == ACTION . RESTORE ) { // Lets ignore the effects of the restore and wait out for the next cycle doAction ( ACTION . NOOP , autoTuneFactor , progress ) ; } }
Tune max default max spout pending based on progress