Skip to content

Commit

Permalink
ignite-6339 WAL write operations are optimized and file IO operations…
Browse files Browse the repository at this point in the history
… are non-interruptible from user thread now
  • Loading branch information
agura committed Dec 25, 2017
1 parent 100bf0b commit a5ffd4e
Show file tree
Hide file tree
Showing 36 changed files with 2,423 additions and 1,107 deletions.
Expand Up @@ -26,7 +26,7 @@ public interface DataStorageMetrics {
* Gets the average number of WAL records per second written during the last time interval. * Gets the average number of WAL records per second written during the last time interval.
* <p> * <p>
* The length of time interval is configured via {@link DataStorageConfiguration#setMetricsRateTimeInterval(long)} * The length of time interval is configured via {@link DataStorageConfiguration#setMetricsRateTimeInterval(long)}
* configurartion property. * configuration property.
* The number of subintervals is configured via {@link DataStorageConfiguration#setMetricsSubIntervalCount(int)} * The number of subintervals is configured via {@link DataStorageConfiguration#setMetricsSubIntervalCount(int)}
* configuration property. * configuration property.
*/ */
Expand All @@ -35,7 +35,7 @@ public interface DataStorageMetrics {
/** /**
* Gets the average number of bytes per second written during the last time interval. * Gets the average number of bytes per second written during the last time interval.
* The length of time interval is configured via {@link DataStorageConfiguration#setMetricsRateTimeInterval(long)} * The length of time interval is configured via {@link DataStorageConfiguration#setMetricsRateTimeInterval(long)}
* configurartion property. * configuration property.
* The number of subintervals is configured via {@link DataStorageConfiguration#setMetricsSubIntervalCount(int)} * The number of subintervals is configured via {@link DataStorageConfiguration#setMetricsSubIntervalCount(int)}
* configuration property. * configuration property.
*/ */
Expand All @@ -50,12 +50,22 @@ public interface DataStorageMetrics {
* Gets the average WAL fsync duration in microseconds over the last time interval. * Gets the average WAL fsync duration in microseconds over the last time interval.
* <p> * <p>
* The length of time interval is configured via {@link DataStorageConfiguration#setMetricsRateTimeInterval(long)} * The length of time interval is configured via {@link DataStorageConfiguration#setMetricsRateTimeInterval(long)}
* configurartion property. * configuration property.
* The number of subintervals is configured via {@link DataStorageConfiguration#setMetricsSubIntervalCount(int)} * The number of subintervals is configured via {@link DataStorageConfiguration#setMetricsSubIntervalCount(int)}
* configuration property. * configuration property.
*/ */
public float getWalFsyncTimeAverage(); public float getWalFsyncTimeAverage();


/**
* Returns WAL buffer poll spins number over the last time interval.
* <p>
* The length of time interval is configured via {@link DataStorageConfiguration#setMetricsRateTimeInterval(long)}
* configuration property.
* The number of subintervals is configured via {@link DataStorageConfiguration#setMetricsSubIntervalCount(int)}
* configuration property.
*/
public long getWalBuffPollSpinsRate();

/** /**
* Gets the duration of the last checkpoint in milliseconds. * Gets the duration of the last checkpoint in milliseconds.
* *
Expand Down
Expand Up @@ -750,6 +750,12 @@ public final class IgniteSystemProperties {
*/ */
public static final String IGNITE_WAL_SERIALIZER_VERSION = "IGNITE_WAL_SERIALIZER_VERSION"; public static final String IGNITE_WAL_SERIALIZER_VERSION = "IGNITE_WAL_SERIALIZER_VERSION";


/**
* Property that indicates should be mapped byte buffer used or not.
* Possible values: {@code true} and {@code false}.
*/
public static final String IGNITE_WAL_MMAP = "IGNITE_WAL_MMAP";

/** /**
* When set to {@code true}, Data store folders are generated only by consistent id, and no consistent ID will be * When set to {@code true}, Data store folders are generated only by consistent id, and no consistent ID will be
* set based on existing data store folders. This option also enables compatible folder generation mode as it was * set based on existing data store folders. This option also enables compatible folder generation mode as it was
Expand Down
Expand Up @@ -124,6 +124,9 @@ public class DataStorageConfiguration implements Serializable {
/** Default thread local buffer size. */ /** Default thread local buffer size. */
public static final int DFLT_TLB_SIZE = 128 * 1024; public static final int DFLT_TLB_SIZE = 128 * 1024;


/** Default thread local buffer size. */
public static final int DFLT_WAL_BUFF_SIZE = DFLT_WAL_SEGMENT_SIZE / 4;

/** Default Wal flush frequency. */ /** Default Wal flush frequency. */
public static final int DFLT_WAL_FLUSH_FREQ = 2000; public static final int DFLT_WAL_FLUSH_FREQ = 2000;


Expand Down Expand Up @@ -205,6 +208,9 @@ public class DataStorageConfiguration implements Serializable {
/** WAl thread local buffer size. */ /** WAl thread local buffer size. */
private int walTlbSize = DFLT_TLB_SIZE; private int walTlbSize = DFLT_TLB_SIZE;


/** WAl buffer size. */
private int walBuffSize/* = DFLT_WAL_BUFF_SIZE*/;

/** Wal flush frequency in milliseconds. */ /** Wal flush frequency in milliseconds. */
private long walFlushFreq = DFLT_WAL_FLUSH_FREQ; private long walFlushFreq = DFLT_WAL_FLUSH_FREQ;


Expand All @@ -230,7 +236,7 @@ public class DataStorageConfiguration implements Serializable {
* rate-based metrics when next sub-interval has to be recycled but introduces bigger * rate-based metrics when next sub-interval has to be recycled but introduces bigger
* calculation overhead. * calculation overhead.
*/ */
private int metricsSubIntervalCount = DFLT_SUB_INTERVALS; private int metricsSubIntervalCnt = DFLT_SUB_INTERVALS;


/** Time interval (in milliseconds) for rate-based metrics. */ /** Time interval (in milliseconds) for rate-based metrics. */
private long metricsRateTimeInterval = DFLT_RATE_TIME_INTERVAL_MILLIS; private long metricsRateTimeInterval = DFLT_RATE_TIME_INTERVAL_MILLIS;
Expand Down Expand Up @@ -648,7 +654,7 @@ public DataStorageConfiguration setMetricsRateTimeInterval(long metricsRateTimeI
* @return The number of sub-intervals for history tracking. * @return The number of sub-intervals for history tracking.
*/ */
public int getMetricsSubIntervalCount() { public int getMetricsSubIntervalCount() {
return metricsSubIntervalCount; return metricsSubIntervalCnt;
} }


/** /**
Expand All @@ -657,7 +663,7 @@ public int getMetricsSubIntervalCount() {
* @param metricsSubIntervalCnt The number of sub-intervals for history tracking. * @param metricsSubIntervalCnt The number of sub-intervals for history tracking.
*/ */
public DataStorageConfiguration setMetricsSubIntervalCount(int metricsSubIntervalCnt) { public DataStorageConfiguration setMetricsSubIntervalCount(int metricsSubIntervalCnt) {
this.metricsSubIntervalCount = metricsSubIntervalCnt; this.metricsSubIntervalCnt = metricsSubIntervalCnt;


return this; return this;
} }
Expand Down Expand Up @@ -706,6 +712,25 @@ public DataStorageConfiguration setWalThreadLocalBufferSize(int walTlbSize) {
return this; return this;
} }


/**
* Property defines size of WAL buffer.
* Each WAL record will be serialized to this buffer before write in WAL file.
*
* @return WAL buffer size.
*/
public int getWalBufferSize() {
return walBuffSize <= 0 ? getWalSegmentSize() / 4 : walBuffSize;
}

/**
* @param walBuffSize WAL buffer size.
*/
public DataStorageConfiguration setWalBufferSize(int walBuffSize) {
this.walBuffSize = walBuffSize;

return this;
}

/** /**
* This property define how often WAL will be fsync-ed in {@code BACKGROUND} mode. Ignored for * This property define how often WAL will be fsync-ed in {@code BACKGROUND} mode. Ignored for
* all other WAL modes. * all other WAL modes.
Expand Down
Expand Up @@ -65,9 +65,6 @@ public class PersistentStoreConfiguration implements Serializable {
/** Default wal mode. */ /** Default wal mode. */
public static final WALMode DFLT_WAL_MODE = WALMode.DEFAULT; public static final WALMode DFLT_WAL_MODE = WALMode.DEFAULT;


/** Default thread local buffer size. */
public static final int DFLT_TLB_SIZE = 128 * 1024;

/** Default Wal flush frequency. */ /** Default Wal flush frequency. */
public static final int DFLT_WAL_FLUSH_FREQ = 2000; public static final int DFLT_WAL_FLUSH_FREQ = 2000;


Expand Down Expand Up @@ -128,8 +125,8 @@ public class PersistentStoreConfiguration implements Serializable {
/** Wal mode. */ /** Wal mode. */
private WALMode walMode = DFLT_WAL_MODE; private WALMode walMode = DFLT_WAL_MODE;


/** WAl thread local buffer size. */ /** WAl buffer size. */
private int tlbSize = DFLT_TLB_SIZE; private int walBuffSize/* = DFLT_WAL_BUFF_SIZE*/;


/** Wal flush frequency in milliseconds. */ /** Wal flush frequency in milliseconds. */
private long walFlushFreq = DFLT_WAL_FLUSH_FREQ; private long walFlushFreq = DFLT_WAL_FLUSH_FREQ;
Expand Down Expand Up @@ -492,20 +489,43 @@ public PersistentStoreConfiguration setWalMode(WALMode walMode) {
} }


/** /**
* Property define size thread local buffer. * Property defines size of WAL buffer.
* Each thread which write to wal have thread local buffer for serialize recode before write in wal. * Each WAL record will be serialized to this buffer before write in WAL file.
* *
* @return Thread local buffer size. * @return WAL buffer size.
* @deprecated Instead {@link #getWalBufferSize()} should be used.
*/ */
@Deprecated
public int getTlbSize() { public int getTlbSize() {
return tlbSize <= 0 ? DFLT_TLB_SIZE : tlbSize; return getWalBufferSize();
} }


/** /**
* @param tlbSize Tlb size. * @param tlbSize WAL buffer size.
* @deprecated Instead {@link #setWalBufferSize(int walBuffSize)} should be used.
*/ */
@Deprecated
public PersistentStoreConfiguration setTlbSize(int tlbSize) { public PersistentStoreConfiguration setTlbSize(int tlbSize) {
this.tlbSize = tlbSize; return setWalBufferSize(tlbSize);
}

/**
* Property defines size of WAL buffer.
* Each WAL record will be serialized to this buffer before write in WAL file.
*
* @return WAL buffer size.
*/
@Deprecated
public int getWalBufferSize() {
return walBuffSize <= 0 ? getWalSegmentSize() / 4 : walBuffSize;
}

/**
* @param walBuffSize WAL buffer size.
*/
@Deprecated
public PersistentStoreConfiguration setWalBufferSize(int walBuffSize) {
this.walBuffSize = walBuffSize;


return this; return this;
} }
Expand Down
Expand Up @@ -43,7 +43,7 @@ public enum RecordType {
/** Checkpoint (begin) record */ /** Checkpoint (begin) record */
CHECKPOINT_RECORD, CHECKPOINT_RECORD,


/** */ /** WAL segment header record. */
HEADER_RECORD, HEADER_RECORD,


// Delta records. // Delta records.
Expand Down Expand Up @@ -187,30 +187,13 @@ public static RecordType fromOrdinal(int ord) {
/** */ /** */
private int size; private int size;


/** */
private int chainSize;

/** */ /** */
@GridToStringExclude @GridToStringExclude
private WALRecord prev; private WALRecord prev;


/** */ /** */
private WALPointer pos; private WALPointer pos;


/**
* @param chainSize Chain size in bytes.
*/
public void chainSize(int chainSize) {
this.chainSize = chainSize;
}

/**
* @return Get chain size in bytes.
*/
public int chainSize() {
return chainSize;
}

/** /**
* @return Previous record in chain. * @return Previous record in chain.
*/ */
Expand Down
Expand Up @@ -34,7 +34,10 @@ public class DataStorageMetricsImpl implements DataStorageMetricsMXBean {
private volatile HitRateMetrics walFsyncTimeDuration; private volatile HitRateMetrics walFsyncTimeDuration;


/** */ /** */
private volatile HitRateMetrics walFsyncTimeNumber; private volatile HitRateMetrics walFsyncTimeNum;

/** */
private volatile HitRateMetrics walBuffPollSpinsNum;


/** */ /** */
private volatile long lastCpLockWaitDuration; private volatile long lastCpLockWaitDuration;
Expand Down Expand Up @@ -118,14 +121,23 @@ public DataStorageMetricsImpl(
if (!metricsEnabled) if (!metricsEnabled)
return 0; return 0;


long numRate = walFsyncTimeNumber.getRate(); long numRate = walFsyncTimeNum.getRate();


if (numRate == 0) if (numRate == 0)
return 0; return 0;


return (float)walFsyncTimeDuration.getRate() / numRate; return (float)walFsyncTimeDuration.getRate() / numRate;
} }


/** {@inheritDoc} */
@Override public long getWalBuffPollSpinsRate() {
if (!metricsEnabled)
return 0;

return walBuffPollSpinsNum.getRate();
}


/** {@inheritDoc} */ /** {@inheritDoc} */
@Override public long getLastCheckpointDuration() { @Override public long getLastCheckpointDuration() {
if (!metricsEnabled) if (!metricsEnabled)
Expand Down Expand Up @@ -281,7 +293,14 @@ public void onFsync(long nanoTime) {
long microseconds = nanoTime / 1_000; long microseconds = nanoTime / 1_000;


walFsyncTimeDuration.onHits(microseconds); walFsyncTimeDuration.onHits(microseconds);
walFsyncTimeNumber.onHit(); walFsyncTimeNum.onHit();
}

/**
* @param num Number.
*/
public void onBuffPollSpin(int num) {
walBuffPollSpinsNum.onHits(num);
} }


/** /**
Expand All @@ -290,8 +309,9 @@ public void onFsync(long nanoTime) {
private void resetRates() { private void resetRates() {
walLoggingRate = new HitRateMetrics((int)rateTimeInterval, subInts); walLoggingRate = new HitRateMetrics((int)rateTimeInterval, subInts);
walWritingRate = new HitRateMetrics((int)rateTimeInterval, subInts); walWritingRate = new HitRateMetrics((int)rateTimeInterval, subInts);
walBuffPollSpinsNum = new HitRateMetrics((int)rateTimeInterval, subInts);


walFsyncTimeDuration = new HitRateMetrics((int)rateTimeInterval, subInts); walFsyncTimeDuration = new HitRateMetrics((int)rateTimeInterval, subInts);
walFsyncTimeNumber = new HitRateMetrics((int)rateTimeInterval, subInts); walFsyncTimeNum = new HitRateMetrics((int)rateTimeInterval, subInts);
} }
} }
Expand Up @@ -35,6 +35,9 @@ public class DataStorageMetricsSnapshot implements DataStorageMetrics {
/** */ /** */
private float walFsyncTimeAvg; private float walFsyncTimeAvg;


/** */
private long walBuffPollSpinsNum;

/** */ /** */
private long lastCpDuration; private long lastCpDuration;


Expand Down Expand Up @@ -67,6 +70,7 @@ public DataStorageMetricsSnapshot(DataStorageMetrics metrics) {
walWritingRate = metrics.getWalWritingRate(); walWritingRate = metrics.getWalWritingRate();
walArchiveSegments = metrics.getWalArchiveSegments(); walArchiveSegments = metrics.getWalArchiveSegments();
walFsyncTimeAvg = metrics.getWalFsyncTimeAverage(); walFsyncTimeAvg = metrics.getWalFsyncTimeAverage();
walBuffPollSpinsNum = metrics.getWalBuffPollSpinsRate();
lastCpDuration = metrics.getLastCheckpointDuration(); lastCpDuration = metrics.getLastCheckpointDuration();
lastCpLockWaitDuration = metrics.getLastCheckpointLockWaitDuration(); lastCpLockWaitDuration = metrics.getLastCheckpointLockWaitDuration();
lastCpMmarkDuration = metrics.getLastCheckpointMarkDuration(); lastCpMmarkDuration = metrics.getLastCheckpointMarkDuration();
Expand Down Expand Up @@ -97,6 +101,11 @@ public DataStorageMetricsSnapshot(DataStorageMetrics metrics) {
return walFsyncTimeAvg; return walFsyncTimeAvg;
} }


/** {@inheritDoc} */
@Override public long getWalBuffPollSpinsRate() {
return walBuffPollSpinsNum;
}

/** {@inheritDoc} */ /** {@inheritDoc} */
@Override public long getLastCheckpointDuration() { @Override public long getLastCheckpointDuration() {
return lastCpDuration; return lastCpDuration;
Expand Down

0 comments on commit a5ffd4e

Please sign in to comment.