Skip to content

Commit 9f78883

Browse files
author
Craig L Russell
committed
Fix performance bug in clusterj logging
creating new objects creates more log records than it needs to Constants.java add environment variable to choose LoggerFactory DomainFieldHandlerImpl.java add guard for logger.debug calls LoggerFactoryService.java allow loading user-defined class for LoggerFactory ColumnImpl.java add guard for logger.debug calls DeMinimisLoggerFactory.java minimalist logger factory DeMinimisLogger.java minimalist logger
1 parent 3de75a7 commit 9f78883

File tree

6 files changed

+115
-11
lines changed

6 files changed

+115
-11
lines changed

storage/ndb/clusterj/clusterj-api/src/main/java/com/mysql/clusterj/Constants.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -22,7 +22,10 @@
2222
*/
2323
public interface Constants {
2424

25-
/** The name of the connection service property */
25+
/** The name of the environment variable to set the logger factory */
26+
static final String ENV_CLUSTERJ_LOGGER_FACTORY_NAME = "CLUSTERJ_LOGGER_FACTORY";
27+
28+
/** The name of the connection service property */
2629
static final String PROPERTY_CLUSTER_CONNECTION_SERVICE = "com.mysql.clusterj.connection.service";
2730

2831
/** The name of the connection string property. For details, see

storage/ndb/clusterj/clusterj-core/src/main/java/com/mysql/clusterj/core/metadata/DomainFieldHandlerImpl.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -295,11 +295,12 @@ public DomainFieldHandlerImpl(DomainTypeHandlerImpl<?> domainTypeHandler, Table
295295
persistentAnnotation = getMethod.getAnnotation(Persistent.class);
296296
if (persistentAnnotation != null) {
297297
nullValue = persistentAnnotation.nullValue();
298-
logger.debug("Persistent nullValue annotation for " + name + " is " + nullValue);
298+
if (logger.isDebugEnabled())
299+
logger.debug("Persistent nullValue annotation for " + name + " is " + nullValue);
299300
}
300301
// convert the string default value to type-specific value
301302
defaultValue = objectOperationHandlerDelegate.getDefaultValueFor(this, columnDefaultValue);
302-
logger.debug("Default null value for " + name + " is " + defaultValue);
303+
if (logger.isDebugEnabled()) logger.debug("Default null value for " + name + " is " + defaultValue);
303304

304305
// set up the null value handler based on the annotation
305306
switch (nullValue) {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved.
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; version 2 of the License.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License
14+
* along with this program; if not, write to the Free Software
15+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16+
*/
17+
18+
package com.mysql.clusterj.core.util;
19+
20+
public class DeMinimisLogger implements Logger {
21+
22+
public DeMinimisLogger() {}
23+
24+
public void detail(String message) {}
25+
public void debug(String message) {}
26+
public void trace(String message) {}
27+
public void info(String message) {System.out.println(message);}
28+
public void warn(String message) {System.err.println(message);}
29+
public void error(String message) {System.err.println(message);}
30+
public void fatal(String message) {System.err.println(message);}
31+
public boolean isDetailEnabled() {return false;}
32+
public boolean isDebugEnabled() {return false;}
33+
public boolean isTraceEnabled() {return false;}
34+
public boolean isInfoEnabled() {return false;}
35+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved.
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; version 2 of the License.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License
14+
* along with this program; if not, write to the Free Software
15+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16+
*/
17+
18+
package com.mysql.clusterj.core.util;
19+
20+
public class DeMinimisLoggerFactory implements LoggerFactory {
21+
22+
private static Logger instance = new DeMinimisLogger();
23+
24+
/** Get an instance of the logger. The logger to get is based on the
25+
* package name of the class. If there is no logger for the package,
26+
* the parent package name is tried, recursively. If there is no logger
27+
* for the topmost package name, an exception is thrown.
28+
* @param cls the class for which to get the logger
29+
* @return the logger for the class
30+
*/
31+
public Logger getInstance(Class<?> cls) {
32+
return instance;
33+
}
34+
35+
/** Get an instance of the logger. The logger is configured
36+
* based on the name. The logger must already exist.
37+
* @param loggerName the name of the logger, normally the package name
38+
* @return the logger
39+
*/
40+
public Logger getInstance(String loggerName) {
41+
return instance;
42+
}
43+
44+
/** Register an instance of the logger.
45+
*
46+
* @param loggerName the name of the logger, normally the package name
47+
*/
48+
public Logger registerLogger(String loggerName) { return instance; }
49+
}

storage/ndb/clusterj/clusterj-core/src/main/java/com/mysql/clusterj/core/util/LoggerFactoryService.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/*
2-
Copyright 2010 Sun Microsystems, Inc.
3-
All rights reserved. Use is subject to license terms.
2+
Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
43
54
This program is free software; you can redistribute it and/or modify
65
it under the terms of the GNU General Public License as published by
@@ -18,14 +17,31 @@
1817

1918
package com.mysql.clusterj.core.util;
2019

20+
import com.mysql.clusterj.Constants;
21+
2122
public class LoggerFactoryService {
2223

2324
/** The factory for creating logger instances. The default is to use
24-
* the JDK14 logging package. If other loggers are desired, change this
25-
* implementation to use a different logger factory.
25+
* the JDK14 logging package. If other loggers are desired, change the
26+
* environment variable to use a different logger factory. To avoid most
27+
* logging overhead, specify
28+
* export CLUSTERJ_LOGGER_FACTORY=com.mysql.clusterj.core.util.DeMinimisLoggerFactory
2629
*/
2730
private static LoggerFactory instance = new JDK14LoggerFactoryImpl();
2831

32+
static {
33+
String loggerFactoryName = System.getenv(Constants.ENV_CLUSTERJ_LOGGER_FACTORY_NAME);
34+
if (loggerFactoryName != null) {
35+
try {
36+
instance = LoggerFactory.class.cast(
37+
LoggerFactory.class.forName(loggerFactoryName)
38+
.newInstance());
39+
} catch (Throwable t) {
40+
System.err.println("ClusterJ user exception: could not load class " + loggerFactoryName);
41+
}
42+
}
43+
}
44+
2945
/** The singleton logger factory.
3046
*
3147
* @return the factory

storage/ndb/clusterj/clusterj-tie/src/main/java/com/mysql/clusterj/tie/ColumnImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program is free software; you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License as published by
@@ -108,7 +108,7 @@ public ColumnImpl(String tableName, ColumnConst ndbColumn) {
108108
this.precision = ndbColumn.getPrecision();
109109
this.scale = ndbColumn.getScale();
110110
this.size = ndbColumn.getSize();
111-
logger.detail("ColumnImpl column type: " + this.columnType);
111+
if (logger.isDetailEnabled()) logger.detail("ColumnImpl column type: " + this.columnType);
112112
switch(ndbColumn.getType()) {
113113
case ColumnConst.Type.Tinyint:
114114
case ColumnConst.Type.Tinyunsigned:

0 commit comments

Comments
 (0)