Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
f2f1281
IGNITE-11584 Batch write into page memory.
xtern May 27, 2019
74d70f2
IGNITE-11584 Code cleanup.
xtern May 27, 2019
cc43474
IGNITE-11584 Code cleanup.
xtern May 28, 2019
36cb9ae
IGNITE-11584 Coode deduplication revert.
xtern May 28, 2019
46ba49f
IGNITE-11584 Code cleanup.
xtern May 28, 2019
57942b1
IGNITE-11584 Reuse list only.
xtern May 30, 2019
15ad82e
IGNITE-11584 Code cleanup.
xtern May 30, 2019
18bd563
IGNITE-11584 Comments.
xtern May 31, 2019
d8a6f7f
IGNITE-11584 Code cleanup.
xtern May 31, 2019
9cacb18
IGNITE-11584 wip
xtern May 31, 2019
b10171e
wip exp
xtern May 31, 2019
ff2d540
wip exp link
xtern May 31, 2019
0fef23c
wip exp link removed
xtern May 31, 2019
569af20
IGNITE-11584 Rework.
xtern Jun 3, 2019
8f0db69
IGNITE-11584 Don't break into more parts.
xtern Jun 4, 2019
81d7d76
IGNITE-11584 Code cleanup.
xtern Jun 4, 2019
6dd61bc
IGNITE-11584 Removed flow-test, added benchmark.
xtern Jun 5, 2019
52e7a4c
IGNITE-11584 Fixed cacheId on data page.
xtern Jun 5, 2019
8366a23
IGNITE-11584 Minor.
xtern Jun 5, 2019
4e7a863
Revert "IGNITE-11584 Fixed cacheId on data page."
xtern Jun 5, 2019
882eb07
IGNITE-11584 Fixed eviction tracker bug by reverting advanced code.
xtern Jun 6, 2019
ca476f4
IGNITE-11584 Fix after rebase.
xtern Jun 7, 2019
76d0bb4
IGNITE-11584 Bench fix after merge.
xtern Jun 7, 2019
f160361
IGNITE-11584 Code cleanup.
xtern Jun 7, 2019
b44d96a
IGNITE-11584 Code cleanup 2.
xtern Jun 7, 2019
024361a
IGNITE-11584 Code cleanup (javadoc).
xtern Jun 10, 2019
eeed6f0
IGNITE-11584 Code cleanup (minor).
xtern Jun 11, 2019
dcf2fb5
IGNITE-11584 Minor.
xtern Jun 11, 2019
7511ca5
IGNITE-11584 Removed redundant groupping by cacheid.
xtern Jun 13, 2019
eff7871
IGNITE-11584 Minor (javadocs).
xtern Jun 14, 2019
b266bba
IGNITE-11584 Minor.
xtern Jun 14, 2019
8f3ab0e
IGNITE-11584 Minor.
xtern Jun 18, 2019
d3023e1
IGNITE-11584 Minor.
xtern Jun 18, 2019
19c0213
IGNITE-11584 Test code cleanup.
xtern Jun 18, 2019
4e57bab
IGNITE-11584 Code cleanup.
xtern Jun 21, 2019
fe0624d
IGNITE-11584 Code cleanup.
xtern Jun 24, 2019
68d4db2
IGNITE-11584 Minor.
xtern Jun 24, 2019
30ea5a0
IGNITE_11584 Minor.
xtern Jun 25, 2019
a9eaa6a
IGNITE_11584 Code cleanup.
xtern Jun 25, 2019
9f67bc1
IGNITE-11584 Code cleanup.
xtern Jun 25, 2019
4e2872a
IGNITE-11584 Minor.
xtern Jun 25, 2019
63c199e
IGNITE-11584 Redundant call.
xtern Jun 25, 2019
99d904a
IGNITE-11584 Use subList instead of arraylist creation, redundant cct…
xtern Jun 25, 2019
c94018f
IGNITE-11584 Minor rework offheap.
xtern Jun 25, 2019
25f28f6
IGNITE-11584 Minor.
xtern Jun 25, 2019
7ece4b8
IGNITE-11584 Minor.
xtern Jun 25, 2019
eb2b88e
IGNITE-11584 Code cleanup.
xtern Jun 25, 2019
c84c727
IGNITE-11584 Code cleanup.
xtern Jun 25, 2019
20147a4
IGNITE-11584 Code cleanup.
xtern Jun 26, 2019
bd3db80
IGNITE-11584 Map experiment.
xtern Jun 26, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,306 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.ignite.internal.benchmarks.jmh.pagemem;

import java.util.AbstractCollection;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteLogger;
import org.apache.ignite.configuration.DataRegionConfiguration;
import org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider;
import org.apache.ignite.internal.pagemem.PageIdAllocator;
import org.apache.ignite.internal.pagemem.PageMemory;
import org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl;
import org.apache.ignite.internal.processors.cache.CacheObjectImpl;
import org.apache.ignite.internal.processors.cache.KeyCacheObjectImpl;
import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow;
import org.apache.ignite.internal.processors.cache.persistence.CacheDataRowAdapter;
import org.apache.ignite.internal.processors.cache.persistence.DataRegion;
import org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl;
import org.apache.ignite.internal.processors.cache.persistence.Storable;
import org.apache.ignite.internal.processors.cache.persistence.evict.NoOpPageEvictionTracker;
import org.apache.ignite.internal.processors.cache.persistence.freelist.CacheFreeList;
import org.apache.ignite.internal.processors.cache.persistence.freelist.FreeList;
import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
import org.apache.ignite.internal.stat.IoStatisticsHolder;
import org.apache.ignite.internal.stat.IoStatisticsHolderNoOp;
import org.apache.ignite.logger.java.JavaLogger;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.annotations.Threads;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

import static java.util.concurrent.TimeUnit.MICROSECONDS;
import static java.util.concurrent.TimeUnit.MILLISECONDS;

/**
* Performance comparision between FreeList.insertRow(..) and FreeList.insertRows(..).
*/
@BenchmarkMode(Mode.AverageTime)
@Fork(value = 1, jvmArgsAppend = {"-Xms1g", "-server", "-XX:+AggressiveOpts", "-XX:MaxMetaspaceSize=256m", "-ea"})
@OutputTimeUnit(MICROSECONDS)
@State(Scope.Benchmark)
@Threads(1)
@Warmup(iterations = 10, time = 200, timeUnit = MILLISECONDS)
@Measurement(iterations = 11, time = 200, timeUnit = MILLISECONDS)
public class JmhCacheFreelistBenchmark {
/** */
private static final long MEMORY_REGION_SIZE = 10 * 1024 * 1024 * 1024L; // 10 GB

/** */
private static final int PAGE_SIZE = 4096;

/** */
private static final int ROWS_COUNT = 200;

/** */
public enum DATA_ROW_SIZE {
/** */
r4_64(4, 64),

/** */
r100_300(100, 300),

/** */
r300_700(300, 700),

/** */
r700_1200(700, 1200),

/** */
r1200_3000(1_200, 3_000),

/** */
r1000_8000(1_000, 8_000),

/** Large objects only. */
r4000_16000(4_000, 16_000),

/** Mixed objects, mostly large objects. */
r100_32000(100, 32_000);

/** */
private final int min;

/** */
private final int max;

/** */
DATA_ROW_SIZE(int min, int max) {
this.min = min;
this.max = max;
}
}

/**
* Check {@link FreeList#insertDataRow(Storable, IoStatisticsHolder)} performance.
*/
@Benchmark
public void insertRow(FreeListProvider provider, Data rows) throws IgniteCheckedException {
for (CacheDataRow row : rows)
provider.freeList.insertDataRow(row, IoStatisticsHolderNoOp.INSTANCE);
}

/**
* Check {@link FreeList#insertDataRows(Collection, IoStatisticsHolder)} performance.
*/
@Benchmark
public void insertRows(FreeListProvider provider, Data rows) throws IgniteCheckedException {
provider.freeList.insertDataRows(rows, IoStatisticsHolderNoOp.INSTANCE);
}

/** */
@State(Scope.Thread)
public static class Data extends AbstractCollection<CacheDataRow> {
/** */
@Param
private DATA_ROW_SIZE range;

/** */
private Collection<CacheDataRow> rows = new ArrayList<>(ROWS_COUNT);

/** */
@Setup(Level.Invocation)
public void prepare() {
Random rnd = ThreadLocalRandom.current();

int randomRange = range.max - range.min;

for (int i = 0; i < ROWS_COUNT; i++) {
int keySize = (range.min + rnd.nextInt(randomRange)) / 2;
int valSize = (range.min + rnd.nextInt(randomRange)) / 2;

CacheDataRow row = new TestDataRow(keySize, valSize);

rows.add(row);
}
}

/** */
@TearDown(Level.Invocation)
public void cleanup() {
rows.clear();
}

/** {@inheritDoc} */
@Override public Iterator<CacheDataRow> iterator() {
return rows.iterator();
}

/** {@inheritDoc} */
@Override public int size() {
return rows.size();
}
}

/** */
@State(Scope.Thread)
public static class FreeListProvider {
/** */
private final DataRegionConfiguration plcCfg =
new DataRegionConfiguration().setInitialSize(MEMORY_REGION_SIZE).setMaxSize(MEMORY_REGION_SIZE);

/** */
private final JavaLogger log = new JavaLogger();

/** */
private PageMemory pageMem;

/** */
private FreeList<CacheDataRow> freeList;

/** */
@Setup(Level.Trial)
public void setup() throws IgniteCheckedException {
pageMem = createPageMemory(log, PAGE_SIZE, plcCfg);

freeList = createFreeList(pageMem, plcCfg);
}

/** */
@TearDown(Level.Trial)
public void tearDown() {
pageMem.stop(true);
}

/**
* @return Page memory.
*/
protected PageMemory createPageMemory(IgniteLogger log, int pageSize, DataRegionConfiguration plcCfg) {
PageMemory pageMem = new PageMemoryNoStoreImpl(log,
new UnsafeMemoryProvider(log),
null,
pageSize,
plcCfg,
new DataRegionMetricsImpl(plcCfg),
true);

pageMem.start();

return pageMem;
}

/**
* @param pageMem Page memory.
* @return Free list.
* @throws IgniteCheckedException If failed.
*/
private FreeList<CacheDataRow> createFreeList(
PageMemory pageMem,
DataRegionConfiguration plcCfg
) throws IgniteCheckedException {
long metaPageId = pageMem.allocatePage(1, 1, PageIdAllocator.FLAG_DATA);

DataRegionMetricsImpl regionMetrics = new DataRegionMetricsImpl(plcCfg);

DataRegion dataRegion = new DataRegion(pageMem, plcCfg, regionMetrics, new NoOpPageEvictionTracker());

return new CacheFreeList(
1,
"freelist",
regionMetrics,
dataRegion,
null,
null,
metaPageId,
true,
null
);
}
}

/** */
private static class TestDataRow extends CacheDataRowAdapter {
/** */
private long link;

/**
* @param keySize Key size.
* @param valSize Value size.
*/
private TestDataRow(int keySize, int valSize) {
super(
new KeyCacheObjectImpl(0, new byte[keySize], 0),
new CacheObjectImpl(0, new byte[valSize]),
new GridCacheVersion(keySize, valSize, 1),
0
);
}

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

/** {@inheritDoc} */
@Override public void link(long link) {
this.link = link;
}
}

/**
* Run benchmark.
*
* @param args Args.
*/
public static void main(String[] args) throws RunnerException {
final Options options = new OptionsBuilder()
.include(JmhCacheFreelistBenchmark.class.getSimpleName())
.build();

new Runner(options).run();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,42 @@ default boolean initialValue(CacheObject val,
* @throws IgniteCheckedException In case of error.
* @throws GridCacheEntryRemovedException If entry was removed.
*/
default boolean initialValue(CacheObject val,
GridCacheVersion ver,
@Nullable MvccVersion mvccVer,
@Nullable MvccVersion newMvccVer,
byte mvccTxState,
byte newMvccTxState,
long ttl,
long expireTime,
boolean preload,
AffinityTopologyVersion topVer,
GridDrType drType,
boolean fromStore) throws IgniteCheckedException, GridCacheEntryRemovedException {
return initialValue(val, ver, null, null, TxState.NA, TxState.NA,
ttl, expireTime, preload, topVer, drType, fromStore, null);
}

/**
* Sets new value if current version is <tt>0</tt>
*
* @param val New value.
* @param ver Version to use.
* @param mvccVer Mvcc version.
* @param newMvccVer New mvcc version.
* @param mvccTxState Tx state hint for mvcc version.
* @param newMvccTxState Tx state hint for new mvcc version.
* @param ttl Time to live.
* @param expireTime Expiration time.
* @param preload Flag indicating whether entry is being preloaded.
* @param topVer Topology version.
* @param drType DR type.
* @param fromStore {@code True} if value was loaded from store.
* @param row Pre-created data row, associated with this cache entry.
* @return {@code True} if initial value was set.
* @throws IgniteCheckedException In case of error.
* @throws GridCacheEntryRemovedException If entry was removed.
*/
public boolean initialValue(CacheObject val,
GridCacheVersion ver,
@Nullable MvccVersion mvccVer,
Expand All @@ -803,7 +839,8 @@ public boolean initialValue(CacheObject val,
boolean preload,
AffinityTopologyVersion topVer,
GridDrType drType,
boolean fromStore) throws IgniteCheckedException, GridCacheEntryRemovedException;
boolean fromStore,
@Nullable CacheDataRow row) throws IgniteCheckedException, GridCacheEntryRemovedException;

/**
* Create versioned entry for this cache entry.
Expand Down
Loading