You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by yz...@apache.org on 2017/07/31 15:23:26 UTC
[8/8] ignite git commit: FreeList striped pool optimisation
FreeList striped pool optimisation
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/66645fe4
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/66645fe4
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/66645fe4
Branch: refs/heads/ignite-5658
Commit: 66645fe499e34b964d8c1679e5cff3dc5af624e1
Parents: b83cb75
Author: Igor Seliverstov <gv...@gmail.com>
Authored: Mon Jul 31 18:12:05 2017 +0300
Committer: Igor Seliverstov <gv...@gmail.com>
Committed: Mon Jul 31 18:12:05 2017 +0300
----------------------------------------------------------------------
.../cache/persistence/freelist/PagesList.java | 60 +++++++++++---------
.../org/apache/ignite/thread/IgniteThread.java | 6 ++
2 files changed, 39 insertions(+), 27 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/66645fe4/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/freelist/PagesList.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/freelist/PagesList.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/freelist/PagesList.java
index 39a6865..15bc4a0 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/freelist/PagesList.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/freelist/PagesList.java
@@ -47,6 +47,7 @@ import org.apache.ignite.internal.util.GridLongList;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.thread.IgniteThread;
import org.jetbrains.annotations.Nullable;
import static java.lang.Boolean.FALSE;
@@ -66,7 +67,7 @@ public abstract class PagesList extends DataStructure {
/** */
private static final int MAX_STRIPES_PER_BUCKET =
IgniteSystemProperties.getInteger("IGNITE_PAGES_LIST_STRIPES_PER_BUCKET",
- Math.min(8, Runtime.getRuntime().availableProcessors() * 2));
+ Math.max(8, Runtime.getRuntime().availableProcessors()));
/** */
protected final AtomicLong[] bucketsSize;
@@ -512,6 +513,16 @@ public abstract class PagesList extends DataStructure {
if (tails == null)
return addStripe(bucket, true);
+ // Striped pool optimization
+ int stripeIdx = IgniteThread.currentStripe();
+
+ if (stripeIdx != -1) {
+ if (stripeIdx >= tails.length)
+ return addStripe(bucket, true);
+
+ return tails[stripeIdx];
+ }
+
return randomTail(tails);
}
@@ -607,12 +618,8 @@ public abstract class PagesList extends DataStructure {
try {
long tailAddr = writeLockPage(tailId, tailPage, bucket, lockAttempt++); // Explicit check.
- if (tailAddr == 0L) {
- if (isReuseBucket(bucket) && lockAttempt == TRY_LOCK_ATTEMPTS)
- addStripeForReuseBucket(bucket);
-
+ if (tailAddr == 0L)
continue;
- }
assert PageIO.getPageId(tailAddr) == tailId : "pageId = " + PageIO.getPageId(tailAddr) + ", tailId = " + tailId;
assert PageIO.getType(tailAddr) == PageIO.T_PAGE_LIST_NODE;
@@ -912,13 +919,26 @@ public abstract class PagesList extends DataStructure {
* @param bucket Bucket index.
* @return Page for take.
*/
- private Stripe getPageForTake(int bucket) {
+ private Stripe getPageForTake(int bucket) throws IgniteCheckedException {
Stripe[] tails = getBucket(bucket);
if (tails == null || bucketsSize[bucket].get() == 0)
return null;
int len = tails.length;
+
+ // Striped pool optimization
+ int stripeIdx = IgniteThread.currentStripe();
+
+ if (stripeIdx != -1) {
+ if (stripeIdx >= len)
+ return addStripe(bucket, !isReuseBucket(bucket));
+
+ Stripe stripe = tails[stripeIdx];
+
+ return stripe.empty ? null : stripe;
+ }
+
int init = randomInt(len);
int cur = init;
@@ -943,6 +963,10 @@ public abstract class PagesList extends DataStructure {
*/
private long writeLockPage(long pageId, long page, int bucket, int lockAttempt)
throws IgniteCheckedException {
+
+ if (IgniteThread.currentStripe() != -1)
+ return writeLock(pageId, page);
+
long pageAddr = tryWriteLock(pageId, page);
if (pageAddr != 0L)
@@ -952,8 +976,7 @@ public abstract class PagesList extends DataStructure {
Stripe[] stripes = getBucket(bucket);
if (stripes == null || stripes.length < MAX_STRIPES_PER_BUCKET) {
- if (!isReuseBucket(bucket))
- addStripe(bucket, true);
+ addStripe(bucket, !isReuseBucket(bucket));
return 0L;
}
@@ -963,19 +986,6 @@ public abstract class PagesList extends DataStructure {
}
/**
- * @param bucket Bucket.
- * @throws IgniteCheckedException If failed.
- */
- private void addStripeForReuseBucket(int bucket) throws IgniteCheckedException {
- assert isReuseBucket(bucket);
-
- Stripe[] stripes = getBucket(bucket);
-
- if (stripes == null || stripes.length < MAX_STRIPES_PER_BUCKET)
- addStripe(bucket, false);
- }
-
- /**
* @param bucket Bucket index.
* @param initIoVers Optional IO to initialize page.
* @return Removed page ID.
@@ -994,12 +1004,8 @@ public abstract class PagesList extends DataStructure {
try {
long tailAddr = writeLockPage(tailId, tailPage, bucket, lockAttempt++); // Explicit check.
- if (tailAddr == 0L) {
- if (isReuseBucket(bucket) && lockAttempt == TRY_LOCK_ATTEMPTS)
- addStripeForReuseBucket(bucket);
-
+ if (tailAddr == 0L)
continue;
- }
if (stripe.empty) {
// Another thread took the last page.
http://git-wip-us.apache.org/repos/asf/ignite/blob/66645fe4/modules/core/src/main/java/org/apache/ignite/thread/IgniteThread.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/thread/IgniteThread.java b/modules/core/src/main/java/org/apache/ignite/thread/IgniteThread.java
index c814625..646abbb 100644
--- a/modules/core/src/main/java/org/apache/ignite/thread/IgniteThread.java
+++ b/modules/core/src/main/java/org/apache/ignite/thread/IgniteThread.java
@@ -148,6 +148,12 @@ public class IgniteThread extends Thread {
this.compositeRwLockIdx = compositeRwLockIdx;
}
+ public static int currentStripe() {
+ Thread thread = Thread.currentThread();
+
+ return thread.getClass() == IgniteThread.class ? ((IgniteThread)thread).stripe : -1;
+ }
+
/**
* Creates new thread name.
*