Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 95407200C1B for ; Tue, 31 Jan 2017 02:11:40 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 93C4B160B60; Tue, 31 Jan 2017 01:11:40 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id B7C82160B4D for ; Tue, 31 Jan 2017 02:11:39 +0100 (CET) Received: (qmail 28459 invoked by uid 500); 31 Jan 2017 01:11:38 -0000 Mailing-List: contact commits-help@bookkeeper.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: bookkeeper-dev@bookkeeper.apache.org Delivered-To: mailing list commits@bookkeeper.apache.org Received: (qmail 28448 invoked by uid 99); 31 Jan 2017 01:11:38 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 31 Jan 2017 01:11:38 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 799FCDFC61; Tue, 31 Jan 2017 01:11:38 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sijie@apache.org To: commits@bookkeeper.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: bookkeeper git commit: BOOKKEEPER-968: Entry log flushes at configurable chunks Date: Tue, 31 Jan 2017 01:11:38 +0000 (UTC) archived-at: Tue, 31 Jan 2017 01:11:40 -0000 Repository: bookkeeper Updated Branches: refs/heads/master ba5dadcb3 -> 26b09abb4 BOOKKEEPER-968: Entry log flushes at configurable chunks With this patch one can configure interval (in bytes) for entry log to flush writes to the disk. Author: Andrey Yegorov Reviewers: Sijie Guo Closes #77 from dlg99/task/entry-log-flush Project: http://git-wip-us.apache.org/repos/asf/bookkeeper/repo Commit: http://git-wip-us.apache.org/repos/asf/bookkeeper/commit/26b09abb Tree: http://git-wip-us.apache.org/repos/asf/bookkeeper/tree/26b09abb Diff: http://git-wip-us.apache.org/repos/asf/bookkeeper/diff/26b09abb Branch: refs/heads/master Commit: 26b09abb4202362ca37d6944ce75eb2a3309dc3c Parents: ba5dadc Author: Andrey Yegorov Authored: Mon Jan 30 17:11:29 2017 -0800 Committer: Sijie Guo Committed: Mon Jan 30 17:11:29 2017 -0800 ---------------------------------------------------------------------- bookkeeper-server/conf/bk_server.conf | 7 +++++ .../apache/bookkeeper/bookie/EntryLogger.java | 23 ++++++++++++++++ .../bookkeeper/conf/ServerConfiguration.java | 28 ++++++++++++++++++++ 3 files changed, 58 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/26b09abb/bookkeeper-server/conf/bk_server.conf ---------------------------------------------------------------------- diff --git a/bookkeeper-server/conf/bk_server.conf b/bookkeeper-server/conf/bk_server.conf index 14c6068..e2a2be6 100644 --- a/bookkeeper-server/conf/bk_server.conf +++ b/bookkeeper-server/conf/bk_server.conf @@ -274,6 +274,13 @@ zkTimeout=10000 # The interval is specified in seconds. #auditorPeriodicBookieCheckInterval=86400 +# Entry log flush interval in bytes. +# Default is 0. 0 or less disables this feature and effectively flush +# happens on log rotation. +# Flushing in smaller chunks but more frequently reduces spikes in disk +# I/O. Flushing too frequently may also affect performance negatively. +#flushEntrylogBytes=0 + # How long to wait, in seconds, before starting auto recovery of a lost bookie #lostBookieRecoveryDelay=0 http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/26b09abb/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/EntryLogger.java ---------------------------------------------------------------------- diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/EntryLogger.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/EntryLogger.java index 08ad1be..3314903 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/EntryLogger.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/EntryLogger.java @@ -171,6 +171,10 @@ public class EntryLogger { final static int MIN_SANE_ENTRY_SIZE = 8 + 8; final static long MB = 1024 * 1024; + private final long flushIntervalInBytes; + private final boolean doRegularFlushes; + private long bytesWrittenSinceLastFlush = 0; + final ServerConfiguration conf; /** * Scan entries in a entry log file. @@ -253,6 +257,9 @@ public class EntryLogger { this.leastUnflushedLogId = logId + 1; this.entryLoggerAllocator = new EntryLoggerAllocator(logId); this.conf = conf; + flushIntervalInBytes = conf.getFlushIntervalInBytes(); + doRegularFlushes = flushIntervalInBytes > 0; + initialize(); } @@ -737,6 +744,7 @@ public class EntryLogger { synchronized void flushCurrentLog() throws IOException { if (logChannel != null) { logChannel.flush(true); + bytesWrittenSinceLastFlush = 0; LOG.debug("Flush and sync current entry logger {}.", logChannel.getLogId()); } } @@ -752,6 +760,9 @@ public class EntryLogger { // Create new log if logSizeLimit reached or current disk is full boolean createNewLog = shouldCreateNewEntryLog.get(); if (createNewLog || reachEntryLogLimit) { + if (doRegularFlushes) { + flushCurrentLog(); + } createNewLog(); // Reset the flag if (createNewLog) { @@ -766,10 +777,22 @@ public class EntryLogger { long pos = logChannel.position(); logChannel.write(entry); logChannel.registerWrittenEntry(ledger, entrySize); + + incrementBytesWrittenAndMaybeFlush(4L + entrySize); return (logChannel.getLogId() << 32L) | pos; } + private void incrementBytesWrittenAndMaybeFlush(long bytesWritten) throws IOException { + if (!doRegularFlushes) { + return; + } + bytesWrittenSinceLastFlush += bytesWritten; + if (bytesWrittenSinceLastFlush > flushIntervalInBytes) { + flushCurrentLog(); + } + } + static long logIdForOffset(long offset) { return offset >> 32L; } http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/26b09abb/bookkeeper-server/src/main/java/org/apache/bookkeeper/conf/ServerConfiguration.java ---------------------------------------------------------------------- diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/conf/ServerConfiguration.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/conf/ServerConfiguration.java index 6bc118a..8ce6908 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/conf/ServerConfiguration.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/conf/ServerConfiguration.java @@ -56,6 +56,7 @@ public class ServerConfiguration extends AbstractConfiguration { protected final static String GC_OVERREPLICATED_LEDGER_WAIT_TIME = "gcOverreplicatedLedgerWaitTime"; // Sync Parameters protected final static String FLUSH_INTERVAL = "flushInterval"; + protected final static String FLUSH_ENTRYLOG_INTERVAL_BYTES = "flushEntrylogBytes"; // Bookie death watch interval protected final static String DEATH_WATCH_INTERVAL = "bookieDeathWatchInterval"; // Ledger Cache Parameters @@ -266,6 +267,33 @@ public class ServerConfiguration extends AbstractConfiguration { } /** + * Set entry log flush interval in bytes. + * + * Default is 0. 0 or less disables this feature and effectively flush + * happens on log rotation. + * + * Flushing in smaller chunks but more frequently reduces spikes in disk + * I/O. Flushing too frequently may also affect performance negatively. + * + * @return Entry log flush interval in bytes + */ + public long getFlushIntervalInBytes() { + return this.getLong(FLUSH_ENTRYLOG_INTERVAL_BYTES, 0); + } + + /** + * Set entry log flush interval in bytes + * + * @param flushInterval in bytes + * @return server configuration + */ + public ServerConfiguration setFlushIntervalInBytes(long flushInterval) { + this.setProperty(FLUSH_ENTRYLOG_INTERVAL_BYTES, Long.toString(flushInterval)); + return this; + } + + + /** * Get bookie death watch interval * * @return watch interval