Return-Path: X-Original-To: apmail-asterixdb-dev-archive@minotaur.apache.org Delivered-To: apmail-asterixdb-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2090F18739 for ; Thu, 6 Aug 2015 23:32:23 +0000 (UTC) Received: (qmail 31339 invoked by uid 500); 6 Aug 2015 23:32:20 -0000 Delivered-To: apmail-asterixdb-dev-archive@asterixdb.apache.org Received: (qmail 31278 invoked by uid 500); 6 Aug 2015 23:32:20 -0000 Mailing-List: contact dev-help@asterixdb.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@asterixdb.incubator.apache.org Delivered-To: mailing list dev@asterixdb.incubator.apache.org Received: (qmail 31267 invoked by uid 99); 6 Aug 2015 23:32:19 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 06 Aug 2015 23:32:19 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 53FD81A9904 for ; Thu, 6 Aug 2015 23:32:19 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.198 X-Spam-Level: ** X-Spam-Status: No, score=2.198 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, MISSING_HEADERS=1.207, T_RP_MATCHES_RCVD=-0.01, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id xccD1lHg364J for ; Thu, 6 Aug 2015 23:32:17 +0000 (UTC) Received: from unhygienix.ics.uci.edu (unhygienix.ics.uci.edu [128.195.14.130]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with ESMTP id 86DA420530 for ; Thu, 6 Aug 2015 23:32:16 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by unhygienix.ics.uci.edu (Postfix) with ESMTP id 86CD3240F84; Thu, 6 Aug 2015 16:30:07 -0700 (PDT) Date: Thu, 6 Aug 2015 16:30:07 -0700 From: "Yingyi Bu (Code Review)" CC: Jenkins , Young-Seok Kim , Ian Maxon Reply-To: buyingyi@gmail.com X-Gerrit-MessageType: merged Subject: Change in hyracks[master]: improve the buffer cache perf. with 1) a better hash functio... X-Gerrit-Change-Id: I296c589a556a9afa7f27c6f560fa07fc4e2c1861 X-Gerrit-ChangeURL: X-Gerrit-Commit: fd434262d10525f0fb9c0088659f9410fd67a8bf In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Content-Disposition: inline User-Agent: Gerrit/2.8.4 Message-Id: <20150806233007.86CD3240F84@unhygienix.ics.uci.edu> Yingyi Bu has submitted this change and it was merged. Change subject: improve the buffer cache perf. with 1) a better hash function for fileid-pageid, 2) reduce synchronization in clock page replacement policy. ...................................................................... improve the buffer cache perf. with 1) a better hash function for fileid-pageid, 2) reduce synchronization in clock page replacement policy. Change-Id: I296c589a556a9afa7f27c6f560fa07fc4e2c1861 Reviewed-on: https://asterix-gerrit.ics.uci.edu/342 Tested-by: Jenkins Reviewed-by: Ian Maxon Reviewed-by: Young-Seok Kim --- M hyracks/hyracks-storage-am-lsm-common/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/common/impls/VirtualBufferCache.java M hyracks/hyracks-storage-common/src/main/java/edu/uci/ics/hyracks/storage/common/buffercache/BufferCache.java M hyracks/hyracks-storage-common/src/main/java/edu/uci/ics/hyracks/storage/common/buffercache/ClockPageReplacementStrategy.java 3 files changed, 30 insertions(+), 32 deletions(-) Approvals: Young-Seok Kim: Looks good to me, approved Ian Maxon: Looks good to me, but someone else must approve Jenkins: Verified diff --git a/hyracks/hyracks-storage-am-lsm-common/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/common/impls/VirtualBufferCache.java b/hyracks/hyracks-storage-am-lsm-common/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/common/impls/VirtualBufferCache.java index d5d04fb..62bf025 100644 --- a/hyracks/hyracks-storage-am-lsm-common/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/common/impls/VirtualBufferCache.java +++ b/hyracks/hyracks-storage-am-lsm-common/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/common/impls/VirtualBufferCache.java @@ -50,9 +50,9 @@ this.allocator = allocator; this.fileMapManager = new TransientFileMapManager(); this.pageSize = pageSize; - this.numPages = numPages; + this.numPages = 2 * (numPages / 2) + 1; - buckets = new CacheBucket[numPages]; + buckets = new CacheBucket[this.numPages]; pages = new ArrayList(); nextFree = 0; open = false; @@ -186,7 +186,8 @@ } private int hash(long dpid) { - return (int) (dpid % buckets.length); + int hashValue = (int) dpid ^ (Integer.reverse((int) (dpid >>> 32)) >>> 1); + return hashValue % buckets.length; } private VirtualPage getOrAllocPage(long dpid) { diff --git a/hyracks/hyracks-storage-common/src/main/java/edu/uci/ics/hyracks/storage/common/buffercache/BufferCache.java b/hyracks/hyracks-storage-common/src/main/java/edu/uci/ics/hyracks/storage/common/buffercache/BufferCache.java index 0ceab64..d973947 100644 --- a/hyracks/hyracks-storage-common/src/main/java/edu/uci/ics/hyracks/storage/common/buffercache/BufferCache.java +++ b/hyracks/hyracks-storage-common/src/main/java/edu/uci/ics/hyracks/storage/common/buffercache/BufferCache.java @@ -441,7 +441,7 @@ } private int hash(long dpid) { - int hashValue = (int) (dpid ^ (dpid >>> 32)); + int hashValue = (int) dpid ^ (Integer.reverse((int) (dpid >>> 32)) >>> 1); return hashValue % pageMap.length; } diff --git a/hyracks/hyracks-storage-common/src/main/java/edu/uci/ics/hyracks/storage/common/buffercache/ClockPageReplacementStrategy.java b/hyracks/hyracks-storage-common/src/main/java/edu/uci/ics/hyracks/storage/common/buffercache/ClockPageReplacementStrategy.java index 611bf48..b5edc8d 100644 --- a/hyracks/hyracks-storage-common/src/main/java/edu/uci/ics/hyracks/storage/common/buffercache/ClockPageReplacementStrategy.java +++ b/hyracks/hyracks-storage-common/src/main/java/edu/uci/ics/hyracks/storage/common/buffercache/ClockPageReplacementStrategy.java @@ -3,9 +3,9 @@ * Licensed 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 from - * + * * 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. @@ -15,22 +15,19 @@ package edu.uci.ics.hyracks.storage.common.buffercache; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; +import java.util.concurrent.atomic.AtomicInteger; public class ClockPageReplacementStrategy implements IPageReplacementStrategy { private static final int MAX_UNSUCCESSFUL_CYCLE_COUNT = 3; - private final Lock lock; private IBufferCacheInternal bufferCache; private int clockPtr; private ICacheMemoryAllocator allocator; - private int numPages = 0; + private AtomicInteger numPages = new AtomicInteger(0); private final int pageSize; private final int maxAllowedNumPages; public ClockPageReplacementStrategy(ICacheMemoryAllocator allocator, int pageSize, int maxAllowedNumPages) { - this.lock = new ReentrantLock(); this.allocator = allocator; this.pageSize = pageSize; this.maxAllowedNumPages = maxAllowedNumPages; @@ -59,16 +56,13 @@ @Override public ICachedPageInternal findVictim() { - lock.lock(); ICachedPageInternal cachedPage = null; - try { - if (numPages >= maxAllowedNumPages) { - cachedPage = findVictimByEviction(); - } else { - cachedPage = allocatePage(); - } - } finally { - lock.unlock(); + int pageCount = getNumPages(); + // pageCount is a lower-bound of numPages. + if (pageCount >= maxAllowedNumPages) { + cachedPage = findVictimByEviction(); + } else { + cachedPage = allocatePage(); } return cachedPage; } @@ -93,7 +87,10 @@ return cPage; } } - clockPtr = (clockPtr + 1) % numPages; + /** + * The clockPtr may miss the last added pages in this round. + */ + clockPtr = (clockPtr + 1) % getNumPages(); if (clockPtr == startClockPtr) { ++cycleCount; } @@ -101,22 +98,22 @@ return null; } + /** + * The number returned here could only be smaller or equal to the actual number + * of pages, because numPages is monotonically incremented. + */ @Override public int getNumPages() { - int retNumPages = 0; - lock.lock(); - try { - retNumPages = numPages; - } finally { - lock.unlock(); - } - return retNumPages; + return numPages.get(); } private ICachedPageInternal allocatePage() { - CachedPage cPage = new CachedPage(numPages, allocator.allocate(pageSize, 1)[0], this); - bufferCache.addPage(cPage); - numPages++; + CachedPage cPage = null; + synchronized (this) { + cPage = new CachedPage(numPages.get(), allocator.allocate(pageSize, 1)[0], this); + bufferCache.addPage(cPage); + numPages.incrementAndGet(); + } AtomicBoolean accessedFlag = getPerPageObject(cPage); if (!accessedFlag.compareAndSet(true, false)) { if (cPage.pinIfGoodVictim()) { -- To view, visit https://asterix-gerrit.ics.uci.edu/342 To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-MessageType: merged Gerrit-Change-Id: I296c589a556a9afa7f27c6f560fa07fc4e2c1861 Gerrit-PatchSet: 4 Gerrit-Project: hyracks Gerrit-Branch: master Gerrit-Owner: Yingyi Bu Gerrit-Reviewer: Ian Maxon Gerrit-Reviewer: Jenkins Gerrit-Reviewer: Yingyi Bu Gerrit-Reviewer: Young-Seok Kim