Keep Ring buffer size small by default and avoid starting disruptor for server connection
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/34f93d77 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/34f93d77 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/34f93d77 Branch: refs/heads/system-catalog Commit: 34f93d77a37ca7c1e6ac96c2dc7970aafe08b960 Parents: db0e1ed Author: Ankit Singhal <ankitsingha...@gmail.com> Authored: Tue Apr 17 15:08:20 2018 +0530 Committer: Ankit Singhal <ankitsingha...@gmail.com> Committed: Tue Apr 17 15:08:20 2018 +0530 ---------------------------------------------------------------------- .../org/apache/phoenix/log/QueryLoggerDisruptor.java | 2 +- .../phoenix/query/ConnectionQueryServicesImpl.java | 15 +++++++++------ .../main/java/org/apache/phoenix/util/QueryUtil.java | 14 ++++++++++++-- 3 files changed, 22 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/34f93d77/phoenix-core/src/main/java/org/apache/phoenix/log/QueryLoggerDisruptor.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/log/QueryLoggerDisruptor.java b/phoenix-core/src/main/java/org/apache/phoenix/log/QueryLoggerDisruptor.java index b548d6c..1f2240e 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/log/QueryLoggerDisruptor.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/log/QueryLoggerDisruptor.java @@ -43,7 +43,7 @@ public class QueryLoggerDisruptor implements Closeable{ private volatile Disruptor<RingBufferEvent> disruptor; private boolean isClosed = false; //number of elements to create within the ring buffer. - private static final int RING_BUFFER_SIZE = 256 * 1024; + private static final int RING_BUFFER_SIZE = 8 * 1024; private static final Log LOG = LogFactory.getLog(QueryLoggerDisruptor.class); private static final String DEFAULT_WAIT_STRATEGY = BlockingWaitStrategy.class.getName(); http://git-wip-us.apache.org/repos/asf/phoenix/blob/34f93d77/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java index 5985705..f5e83f2 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java @@ -195,7 +195,6 @@ import org.apache.phoenix.schema.ColumnFamilyNotFoundException; import org.apache.phoenix.schema.EmptySequenceCacheException; import org.apache.phoenix.schema.FunctionNotFoundException; import org.apache.phoenix.schema.MetaDataClient; -import org.apache.phoenix.schema.MetaDataSplitPolicy; import org.apache.phoenix.schema.NewerSchemaAlreadyExistsException; import org.apache.phoenix.schema.NewerTableAlreadyExistsException; import org.apache.phoenix.schema.PColumn; @@ -243,6 +242,7 @@ import org.apache.phoenix.util.PhoenixContextExecutor; import org.apache.phoenix.util.PhoenixRuntime; import org.apache.phoenix.util.PhoenixStopWatch; import org.apache.phoenix.util.PropertiesUtil; +import org.apache.phoenix.util.QueryUtil; import org.apache.phoenix.util.ReadOnlyProps; import org.apache.phoenix.util.SchemaUtil; import org.apache.phoenix.util.ServerUtil; @@ -406,11 +406,14 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement this.maxConnectionsAllowed = config.getInt(QueryServices.CLIENT_CONNECTION_MAX_ALLOWED_CONNECTIONS, QueryServicesOptions.DEFAULT_CLIENT_CONNECTION_MAX_ALLOWED_CONNECTIONS); this.shouldThrottleNumConnections = (maxConnectionsAllowed > 0); - try { - this.queryDisruptor = new QueryLoggerDisruptor(this.config); - } catch (SQLException e) { - logger.warn("Unable to initiate qeuery logging service !!"); - e.printStackTrace(); + if (!QueryUtil.isServerConnection(props)) { + //Start queryDistruptor everytime as log level can be change at connection level as well, but we can avoid starting for server connections. + try { + this.queryDisruptor = new QueryLoggerDisruptor(this.config); + } catch (SQLException e) { + logger.warn("Unable to initiate qeuery logging service !!"); + e.printStackTrace(); + } } } http://git-wip-us.apache.org/repos/asf/phoenix/blob/34f93d77/phoenix-core/src/main/java/org/apache/phoenix/util/QueryUtil.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/QueryUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/QueryUtil.java index d7154a1..9d2e53c 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/util/QueryUtil.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/util/QueryUtil.java @@ -82,6 +82,7 @@ public final class QueryUtil { */ public static final int DATA_TYPE_NAME_POSITION = 6; + public static final String IS_SERVER_CONNECTION = "IS_SERVER_CONNECTION"; private static final String SELECT = "SELECT"; private static final String FROM = "FROM"; private static final String WHERE = "WHERE"; @@ -358,6 +359,15 @@ public final class QueryUtil { SQLException { return getConnectionOnServer(new Properties(), conf); } + + public static void setServerConnection(Properties props){ + UpgradeUtil.doNotUpgradeOnFirstConnection(props); + props.setProperty(IS_SERVER_CONNECTION, Boolean.TRUE.toString()); + } + + public static boolean isServerConnection(ReadOnlyProps props) { + return props.getBoolean(IS_SERVER_CONNECTION, false); + } /** * @return {@link PhoenixConnection} with {@value UpgradeUtil#DO_NOT_UPGRADE} set so that we don't initiate metadata upgrade. @@ -365,13 +375,13 @@ public final class QueryUtil { public static Connection getConnectionOnServer(Properties props, Configuration conf) throws ClassNotFoundException, SQLException { - UpgradeUtil.doNotUpgradeOnFirstConnection(props); + setServerConnection(props); return getConnection(props, conf); } public static Connection getConnectionOnServerWithCustomUrl(Properties props, String principal) throws SQLException, ClassNotFoundException { - UpgradeUtil.doNotUpgradeOnFirstConnection(props); + setServerConnection(props); String url = getConnectionUrl(props, null, principal); LOG.info("Creating connection with the jdbc url: " + url); return DriverManager.getConnection(url, props);