private long findOptimalWindowSize(long periodMs, long nearestMultipleOfMinTimeslotSize) {
        final double idealTimeslotSize = (double)periodMs / this.idealNumTimeslots;
        final long timeslotSizeToCompare = nearestMultipleOfMinTimeslotSize < idealTimeslotSize ? 
                nearestMultipleOfMinTimeslotSize + this.minTimeslot : nearestMultipleOfMinTimeslotSize - this.minTimeslot;
        if (Math.abs(nearestMultipleOfMinTimeslotSize - idealTimeslotSize) / ((double)nearestMultipleOfMinTimeslotSize / this.minTimeslot) <
                Math.abs(timeslotSizeToCompare - idealTimeslotSize) / ((double)timeslotSizeToCompare / this.minTimeslot)) {
            return nearestMultipleOfMinTimeslotSize;
        } else {
            return timeslotSizeToCompare;
        }
    }
<p>This implementation returns the window size that would generate the number of timeslots closest to 
<tt>idealNumTimeslots</tt> for a given <tt>range</tt>.
<p>Additionally, the window size is generated in multiples of
<tt>minTimeslot</tt>.

@param durationMillis range to calculate the time window over
@return size of the ideal time window
commons-timeseries/src/main/java/com/navercorp/pinpoint/common/timeseries/window/TimeWindowSlotCentricSampler.java