mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
fixing histolog classes
This commit is contained in:
committed by
Jonathan Shook
parent
bfd15818f9
commit
2771ef60e9
@@ -20,6 +20,7 @@ import io.nosqlbench.api.labels.NBLabels;
|
||||
import io.nosqlbench.api.engine.metrics.DeltaHdrHistogramReservoir;
|
||||
import io.nosqlbench.api.engine.metrics.HistoIntervalLogger;
|
||||
import io.nosqlbench.api.engine.metrics.instruments.NBMetricHistogram;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import org.HdrHistogram.EncodableHistogram;
|
||||
import org.HdrHistogram.Histogram;
|
||||
import org.HdrHistogram.HistogramLogReader;
|
||||
@@ -41,7 +42,7 @@ public class HistoIntervalLoggerTest {
|
||||
File tempFile = File.createTempFile("testhistointlog", "hdr", new File("/tmp"));
|
||||
tempFile.deleteOnExit();
|
||||
|
||||
HistoIntervalLogger hil = new HistoIntervalLogger("loggertest", tempFile, Pattern.compile(".*"), 1000);
|
||||
HistoIntervalLogger hil = new HistoIntervalLogger(new NBBaseComponent(null), "loggertest", tempFile, Pattern.compile(".*"), 1000);
|
||||
|
||||
final int significantDigits = 4;
|
||||
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 nosqlbench
|
||||
*
|
||||
* 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 at
|
||||
*
|
||||
* 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.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.engine.extensions.histostatslogger;
|
||||
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.script.ScriptContext;
|
||||
|
||||
public class HistoStatsPlugin {
|
||||
|
||||
private final Logger logger;
|
||||
private final NBComponent baseComponent;
|
||||
|
||||
public HistoStatsPlugin(Logger logger, NBComponent baseComponent) {
|
||||
this.logger = logger;
|
||||
this.baseComponent = baseComponent;
|
||||
}
|
||||
|
||||
public void logHistoStats(String sessionComment, String pattern, String filename , String interval) {
|
||||
throw new RuntimeException("replace me after merge");
|
||||
// ActivityMetrics.addStatsLogger(sessionComment, pattern, filename, interval);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2023 nosqlbench
|
||||
*
|
||||
* 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 at
|
||||
*
|
||||
* 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.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.engine.extensions.histostatslogger;
|
||||
|
||||
import io.nosqlbench.api.config.LabeledScenarioContext;
|
||||
import io.nosqlbench.api.extensions.ScriptingExtensionPluginInfo;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@Service(value = ScriptingExtensionPluginInfo.class, selector = "histostatslogger")
|
||||
public class HistoStatsPluginData implements ScriptingExtensionPluginInfo<HistoStatsPlugin> {
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "allows script control of histogram stats logging in CSV files";
|
||||
}
|
||||
|
||||
@Override
|
||||
public HistoStatsPlugin getExtensionObject(final Logger logger, final NBComponent baseComponent) {
|
||||
return new HistoStatsPlugin(logger,baseComponent);
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
histostatslogger extension
|
||||
==========================
|
||||
|
||||
This extension allows you to record periodic histogram stats for
|
||||
a matching set of histogram or timer metrics, at some interval you specify.
|
||||
|
||||
### Example
|
||||
~~~
|
||||
histostatslogger.logHistoStats("test run 42", ".*", "logs/histostats
|
||||
.csv", "0.5s");
|
||||
~~~
|
||||
|
||||
The arguments to logHistoStats are:
|
||||
**logHistoStats( *comment*, *regex*, *filename*, *interval* )**, where the fields are:
|
||||
|
||||
- comment - a session or comment name, which is required. When this API is invoked from the command line via --log-histostats, the session name is simply the name of the scenario session.
|
||||
- regex - a regular expression that is used to match metric names. The value '.*' matches everything.
|
||||
- filename - the name of a file to log the statistics to.
|
||||
- interval - the interval size of each row written.
|
||||
|
||||
All matching metrics that are capable of HDR histograms (all histograms and timers in this runtime) that also match the metric name in the pattern will be logged, at the interval provided.
|
||||
|
||||
The format looks like this, similar to that of an HdrHistogram log,
|
||||
with the same support for tags:
|
||||
~~~
|
||||
#logging stats for session testing extention histostatslogger
|
||||
#[Histogram log format version 1.0]
|
||||
#[StartTime: 1479151175.380 (seconds since epoch), Mon Nov 14 13:19:35 CST 2016]
|
||||
#Tag,Interval_Start,Interval_Length,count,min,p25,p50,p75,p90,p95,p98,p99,p999,p9999,max
|
||||
Tag=testhistostatslogger.delay,0.047,0.457,1,16,31,31,31,31,31,31,31,31,31,31
|
||||
Tag=testhistostatslogger.cycles,0.076,0.430,4490,1024,8191,8191,8191,8191,8191,8191,8191,8191,8191,8388607
|
||||
...
|
||||
~~~
|
||||
@@ -17,6 +17,8 @@
|
||||
package io.nosqlbench.api.engine.metrics;
|
||||
|
||||
import com.codahale.metrics.*;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -25,10 +27,14 @@ import java.util.Map;
|
||||
* A silly class that does nothing but allow cleaner code elsewhere,
|
||||
* because MetricRegistryListener, that's why.
|
||||
*/
|
||||
public abstract class CapabilityHook<T> implements MetricRegistryListener {
|
||||
public abstract class CapabilityHook<T> extends NBBaseComponent implements MetricRegistryListener {
|
||||
|
||||
private final Map<String,T> capables = new HashMap<>();
|
||||
|
||||
public CapabilityHook(NBComponent parentComponent) {
|
||||
super(parentComponent);
|
||||
}
|
||||
|
||||
public abstract void onCapableAdded(String name, T capable);
|
||||
public abstract void onCapableRemoved(String name, T capable);
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package io.nosqlbench.api.engine.metrics;
|
||||
|
||||
import com.codahale.metrics.*;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
@@ -36,7 +37,8 @@ public class ClassicHistoListener extends CapabilityHook<HistogramAttachment> {
|
||||
private final TimeUnit nanoseconds;
|
||||
private final Map<String, Attachment> histos = new HashMap<>();
|
||||
|
||||
public ClassicHistoListener(MetricRegistry metricRegistry, String sessionName, String prefix, Pattern pattern, String interval, TimeUnit nanoseconds) {
|
||||
public ClassicHistoListener(NBComponent parent, MetricRegistry metricRegistry, String sessionName, String prefix, Pattern pattern, String interval, TimeUnit nanoseconds) {
|
||||
super(parent);
|
||||
this.metricsRegistry = metricRegistry;
|
||||
this.sessionName = sessionName;
|
||||
this.prefix = prefix;
|
||||
|
||||
@@ -19,6 +19,7 @@ package io.nosqlbench.api.engine.metrics;
|
||||
import com.codahale.metrics.ExponentiallyDecayingReservoir;
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import com.codahale.metrics.Timer;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
@@ -38,7 +39,9 @@ public class ClassicTimerListener extends CapabilityHook<TimerAttachment> {
|
||||
private final TimeUnit nanoseconds;
|
||||
private final Map<String, Attachment> histos = new HashMap<>();
|
||||
|
||||
public ClassicTimerListener(MetricRegistry metricRegistry, String sessionName, String prefix, Pattern pattern, String interval, TimeUnit nanoseconds) {
|
||||
public ClassicTimerListener(NBComponent parent, MetricRegistry metricRegistry, String sessionName, String prefix,
|
||||
Pattern pattern, String interval, TimeUnit nanoseconds) {
|
||||
super(parent);
|
||||
this.metricsRegistry = metricRegistry;
|
||||
this.sessionName = sessionName;
|
||||
this.prefix = prefix;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package io.nosqlbench.api.engine.metrics;
|
||||
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import org.HdrHistogram.EncodableHistogram;
|
||||
import org.HdrHistogram.HistogramLogWriter;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -34,7 +35,7 @@ import java.util.regex.Pattern;
|
||||
* which both match the pattern and which are {@link EncodableHistogram}s are written the configured
|
||||
* logfile at the configured interval.
|
||||
*/
|
||||
public class HistoIntervalLogger extends CapabilityHook<HdrDeltaHistogramAttachment> implements Runnable, MetricsCloseable {
|
||||
public class HistoIntervalLogger extends CapabilityHook<HdrDeltaHistogramAttachment> implements Runnable, MetricsCloseable {
|
||||
private final static Logger logger = LogManager.getLogger(HistoIntervalLogger.class);
|
||||
|
||||
private final String sessionName;
|
||||
@@ -54,7 +55,8 @@ public class HistoIntervalLogger extends CapabilityHook<HdrDeltaHistogramAttach
|
||||
private PeriodicRunnable<HistoIntervalLogger> executor;
|
||||
private long lastRunTime;
|
||||
|
||||
public HistoIntervalLogger(String sessionName, File file, Pattern pattern, long intervalLength) {
|
||||
public HistoIntervalLogger(NBComponent parent, String sessionName, File file, Pattern pattern, long intervalLength) {
|
||||
super(parent);
|
||||
this.sessionName = sessionName;
|
||||
this.logfile = file;
|
||||
this.pattern = pattern;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package io.nosqlbench.api.engine.metrics;
|
||||
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import org.HdrHistogram.EncodableHistogram;
|
||||
import org.HdrHistogram.Histogram;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -49,7 +50,8 @@ public class HistoStatsLogger extends CapabilityHook<HdrDeltaHistogramAttachment
|
||||
private PeriodicRunnable<HistoStatsLogger> executor;
|
||||
private long lastRunTime=0L;
|
||||
|
||||
public HistoStatsLogger(String sessionName, File file, Pattern pattern, long intervalLength, TimeUnit timeUnit) {
|
||||
public HistoStatsLogger(NBComponent parent, String sessionName, File file, Pattern pattern, long intervalLength, TimeUnit timeUnit) {
|
||||
super(parent);
|
||||
this.sessionName = sessionName;
|
||||
this.logfile = file;
|
||||
this.pattern = pattern;
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
package io.nosqlbench.api.histologger;
|
||||
package io.nosqlbench.api.histo;
|
||||
|
||||
import io.nosqlbench.api.engine.metrics.HistoIntervalLogger;
|
||||
import io.nosqlbench.api.engine.util.Unit;
|
||||
@@ -41,6 +41,7 @@ public class HdrHistoLog extends NBBaseComponent {
|
||||
new RuntimeException("Unable to parse interval spec:'" + interval + '\''));
|
||||
|
||||
HistoIntervalLogger histoIntervalLogger =
|
||||
new HistoIntervalLogger(session, logfile, compiledPattern, intervalMillis);
|
||||
new HistoIntervalLogger(this, session, logfile, compiledPattern, intervalMillis);
|
||||
this.attachChild(histoIntervalLogger);
|
||||
}
|
||||
}
|
||||
49
nb-api/src/main/java/io/nosqlbench/api/histo/HistoStats.java
Normal file
49
nb-api/src/main/java/io/nosqlbench/api/histo/HistoStats.java
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2023 nosqlbench
|
||||
*
|
||||
* 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 at
|
||||
*
|
||||
* 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.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.nosqlbench.api.histo;
|
||||
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import io.nosqlbench.api.engine.metrics.HistoStatsLogger;
|
||||
import io.nosqlbench.api.engine.util.Unit;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class HistoStats extends NBBaseComponent {
|
||||
|
||||
public HistoStats(NBComponent baseComponent) {
|
||||
super(baseComponent);
|
||||
}
|
||||
|
||||
public void logHistoStats(String sessionComment, String pattern, String filename , String interval) {
|
||||
if (filename.contains("_SESSION_")) {
|
||||
filename = filename.replace("_SESSION_", sessionComment);
|
||||
}
|
||||
Pattern compiledPattern = Pattern.compile(pattern);
|
||||
File logfile = new File(filename);
|
||||
long intervalMillis = Unit.msFor(interval).orElseThrow(() ->
|
||||
new RuntimeException("Unable to parse interval spec:" + interval + '\''));
|
||||
|
||||
HistoStatsLogger histoStatsLogger =
|
||||
new HistoStatsLogger(this, sessionComment, logfile, compiledPattern, intervalMillis, TimeUnit.NANOSECONDS);
|
||||
this.attachChild(histoStatsLogger);
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,8 @@ import io.nosqlbench.api.engine.metrics.reporters.CsvReporter;
|
||||
import io.nosqlbench.api.engine.metrics.instruments.*;
|
||||
import io.nosqlbench.api.engine.metrics.reporters.MetricInstanceFilter;
|
||||
import io.nosqlbench.api.engine.metrics.reporters.PromPushReporterComponent;
|
||||
import io.nosqlbench.api.histologger.HdrHistoLog;
|
||||
import io.nosqlbench.api.histo.HdrHistoLog;
|
||||
import io.nosqlbench.api.histo.HistoStats;
|
||||
import io.nosqlbench.api.optimizers.BobyqaOptimizerInstance;
|
||||
import io.nosqlbench.api.files.FileAccess;
|
||||
import io.nosqlbench.api.labels.NBLabels;
|
||||
@@ -139,6 +140,10 @@ public class NBBuilders {
|
||||
return new HdrHistoLog(component);
|
||||
}
|
||||
|
||||
public HistoStats histoStats(NBComponent component) {
|
||||
return new HistoStats(component);
|
||||
}
|
||||
|
||||
public static class CsvOutputWriterBuilder {
|
||||
//CsvOutputPluginWriter(NBComponent component, String filename, String... headers) {
|
||||
private final NBComponent component;
|
||||
|
||||
Reference in New Issue
Block a user