- Timestamp:
- 12/08/13 14:12:21 (8 years ago)
- Location:
- Tests/JAVA/logger
- Files:
-
- 1 added
- 2 deleted
- 18 edited
- 1 copied
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
Tests/JAVA/logger/logger.iml
r586 r590 1 1 <?xml version="1.0" encoding="UTF-8"?> 2 2 <module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> 3 <component name="NewModuleRootManager" inherit-compiler-output="false">3 <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="false"> 4 4 <output url="file://$MODULE_DIR$/target/classes" /> 5 5 <output-test url="file://$MODULE_DIR$/target/test-classes" /> … … 7 7 <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> 8 8 <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> 9 <sourceFolder url="file://$MODULE_DIR$/target/generated-test-sources/test-annotations" isTestSource="true" />10 9 <sourceFolder url="file://$MODULE_DIR$/target/generated-sources/annotations" isTestSource="false" /> 11 10 <excludeFolder url="file://$MODULE_DIR$/target/classes" /> 12 <excludeFolder url="file://$MODULE_DIR$/target/maven-archiver" />13 11 <excludeFolder url="file://$MODULE_DIR$/target/maven-status" /> 14 <excludeFolder url="file://$MODULE_DIR$/target/test-classes" />15 12 </content> 16 13 <orderEntry type="inheritedJdk" /> 17 14 <orderEntry type="sourceFolder" forTests="false" /> 18 <orderEntry type="library" name="Maven: org.openjdk.jmh:jmh-core: 1.0-SNAPSHOT" level="project" />15 <orderEntry type="library" name="Maven: org.openjdk.jmh:jmh-core:0.2" level="project" /> 19 16 <orderEntry type="library" name="Maven: args4j:args4j:2.0.16" level="project" /> 20 17 <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.11" level="project" /> -
Tests/JAVA/logger/pom.xml
r586 r590 64 64 <groupId>org.openjdk.jmh</groupId> 65 65 <artifactId>jmh-core</artifactId> 66 <version> 1.0-SNAPSHOT</version>66 <version>0.2</version> 67 67 </dependency> 68 68 <!-- testing support --> -
Tests/JAVA/logger/src/main/java/com/db/logger/api/FastLogger.java
r589 r590 7 7 public interface FastLogger { 8 8 9 public LogMessage messageSimple( final String messageFormat ); 10 11 public LogMessage messageThreadLocal( final String messageFormat ); 12 9 13 public LogMessage message( final String messageFormat ); 10 14 -
Tests/JAVA/logger/src/main/java/com/db/logger/api/impl/logger/FastLoggerImpl.java
r589 r590 3 3 import java.io.IOException; 4 4 import java.nio.ByteBuffer; 5 import java.util.*;6 5 import java.util.concurrent.ThreadFactory; 7 6 8 7 import com.db.logger.api.FastLogger; 8 import com.db.logger.api.FluentLogBuilder; 9 import com.db.logger.api.LogMessage; 9 10 import com.db.logger.api.impl.logger.buffer.ILongsBuffer; 11 import com.db.logger.api.impl.logger.formatters.FlyweightLogMessage; 12 import com.db.logger.api.impl.logger.formatters.RawLogMessage; 10 13 import com.db.logger.api.impl.logger.formatters.SimpleLogMessage; 11 14 import com.db.logger.io.storage.RawWriter; 12 15 import com.google.common.base.Throwables; 13 import gnu.trove.map.hash.T ObjectIntHashMap;16 import gnu.trove.map.hash.THashMap; 14 17 import org.apache.commons.logging.Log; 15 18 import org.apache.commons.logging.LogFactory; … … 23 26 * created 24.08.13 at 15:14 24 27 */ 25 public class SimpleFastLogger implements FastLogger { 26 private static final Log log = LogFactory.getLog( SimpleFastLogger.class ); 27 private static final int NOT_FOUND = -1; 28 public class FastLoggerImpl implements FastLogger { 29 private static final Log log = LogFactory.getLog( FastLoggerImpl.class ); 28 30 29 31 private final ThreadFactory threadFactory; … … 34 36 35 37 36 public SimpleFastLogger( final ThreadFactory threadFactory,37 38 39 38 public FastLoggerImpl( final ThreadFactory threadFactory, 39 final ILongsBuffer buffer, 40 final WaitingStrategy waitingStrategy, 41 final RawWriter writer ) { 40 42 checkArgument( threadFactory != null, "threadFactory can't be null" ); 41 43 checkArgument( waitingStrategy != null, "waitingStrategy can't be null" ); … … 63 65 // }; 64 66 65 private final HashMap<String, SimpleLogMessage> formatters = new HashMap<String, SimpleLogMessage>();66 private final TObjectIntHashMap<String> formatsToID = new TObjectIntHashMap<String>( 128, 0.5f, NOT_FOUND );67 68 69 67 @Override 70 public synchronized SimpleLogMessage message( final String messageFormat ) { 71 int formatId = formatsToID.get( messageFormat ); 72 if( formatId == NOT_FOUND ) { 73 formatId = formatsToID.size() + 1; 74 formatsToID.put( messageFormat, formatId ); 75 } 76 final int argumentsCount = calculateArgumentsCount( messageFormat ); 68 public synchronized SimpleLogMessage messageSimple( final String messageFormat ) { 69 final MessageInfo messageInfo = lookupMessageInfo( messageFormat ); 77 70 return new SimpleLogMessage( 78 71 messageFormat, 79 formatId,80 argumentsCount,72 messageInfo.formatId, 73 messageInfo.argumentsCount, 81 74 circularBuffer 82 75 ); 76 } 77 78 private final ThreadLocal<RawLogMessage> holder = new ThreadLocal<RawLogMessage>() { 79 @Override 80 protected RawLogMessage initialValue() { 81 return new RawLogMessage( circularBuffer ); 82 } 83 }; 84 85 86 @Override 87 public synchronized LogMessage messageThreadLocal( final String messageFormat ) { 88 final MessageInfo messageInfo = lookupMessageInfo( messageFormat ); 89 90 return new ThreadLocalLogMessage( messageInfo ); 91 } 92 93 private final THashMap<String, MessageInfo> formats = new THashMap<String, MessageInfo>( 128 ); 94 95 public LogMessage message( final String messageFormat ) { 96 final MessageInfo messageInfo = lookupMessageInfo( messageFormat ); 97 final RawLogMessage message = holder.get(); 98 return message.setup( messageInfo ).start(); 99 } 100 101 public MessageInfo lookupMessageInfo( final String messageFormat ) { 102 //TODO RC: dcl, ok for testing, but needs rewrite 103 MessageInfo messageInfo = formats.get( messageFormat ); 104 if( messageInfo == null ) { 105 synchronized( formats ) { 106 messageInfo = formats.get( messageFormat ); 107 if( messageInfo == null ) { 108 checkArgument( messageFormat != null, "messageFormat can't be null" ); 109 messageInfo = new MessageInfo( 110 messageFormat, 111 calculateArgumentsCount( messageFormat ), 112 formats.size() + 1 113 ); 114 formats.put( messageFormat, messageInfo ); 115 } 116 } 117 } 118 return messageInfo; 83 119 } 84 120 … … 86 122 int argumentsCount = 0; 87 123 for( int i = 0; i < formatMessage.length(); i++ ) { 88 if( formatMessage.charAt( i ) == '%' ) { 124 if( formatMessage.charAt( i ) == '%' ) {//TODO RC: not safe! '%%' is not placeholder 89 125 argumentsCount++; 90 126 } … … 99 135 final Drainer drainer = new Drainer( 100 136 circularBuffer, new ConsumingDrainer( 101 102 103 137 circularBuffer.buffer(), 138 writer 139 ) 104 140 ); 105 141 drainerThread = threadFactory.newThread( … … 118 154 drainerThread = null; 119 155 } 120 }121 122 protected CircularBuffer getCircularBuffer() {123 return circularBuffer;124 156 } 125 157 … … 227 259 final int formatId = formatId( header ); 228 260 final int argumentsCount = argumentsCount( header ); 261 262 //ensure output has space 229 263 if( output.remaining() < ( argumentsCount + 1 ) * 8 ) { 230 264 writer.flush(); … … 235 269 for( int i = 0; i <= argumentsCount; i++ ) { 236 270 final long arg = buffer.get( pos + i ); 237 //TODO RC: it is not required since Sequencer protect us?238 271 buffer.put( pos + i, NOT_SET );//need to reclaim each cell! 239 272 output.putLong( arg ); … … 258 291 } 259 292 } 293 294 295 private final class ThreadLocalLogMessage implements LogMessage { 296 297 private final MessageInfo messageInfo; 298 299 private ThreadLocalLogMessage( final MessageInfo messageInfo ) { 300 this.messageInfo = messageInfo; 301 } 302 303 @Override 304 public FluentLogBuilder with( final double value ) { 305 return setupLocal().with( value ); 306 } 307 308 @Override 309 public FluentLogBuilder with( final long value ) { 310 return setupLocal().with( value ); 311 } 312 313 @Override 314 public void log() { 315 setupLocal().log(); 316 } 317 318 private RawLogMessage setupLocal() { 319 final RawLogMessage formatter = holder.get(); 320 return formatter.setup( messageInfo ).start(); 321 } 322 323 @Override 324 public String format() { 325 return messageInfo.format; 326 } 327 328 @Override 329 public int argumentsCount() { 330 return messageInfo.argumentsCount; 331 } 332 } 260 333 } -
Tests/JAVA/logger/src/main/java/com/db/logger/api/impl/logger/formatters/AbstractLogBuilder.java
r589 r590 37 37 @Override 38 38 public FluentLogBuilder with( final long value ) { 39 checkState( position != INVALID_INDEX, "Not started");39 ensureStarted(); 40 40 // checkState( 41 41 // argumentIndex < argumentsCount(), 42 // "Only %s arguments allowed but %s is",43 // argumentsCount(), argumentIndex 42 // "Only %s arguments allowed but %s (%s) here", 43 // argumentsCount(), argumentIndex, value 44 44 // ); 45 45 … … 55 55 @Override 56 56 public void log() { 57 checkState( position != INVALID_INDEX, "Not started");57 ensureStarted(); 58 58 try { 59 59 // checkState( … … 70 70 buffer.buffer().putOrdered( position, header ); 71 71 } finally { 72 argumentIndex = NOT_SET; 73 position = INVALID_INDEX; 72 reset(); 74 73 } 75 74 } 76 75 77 protected void start() { 78 checkState( argumentIndex == NOT_SET, "Can't start -- not submitted yet" ); 76 protected void reset() { 77 argumentIndex = NOT_SET; 78 position = INVALID_INDEX; 79 } 79 80 80 position = buffer.claim( argumentsCount() + 1 );//1 for header 81 protected void ensureStarted() { 82 if( position == INVALID_INDEX ) { 83 position = buffer.claim( argumentsCount() + 1 );//1 for header 84 checkState( position != INVALID_INDEX, "Claim failed" ); 81 85 82 argumentIndex = 0; 86 argumentIndex = 0; 87 } 83 88 } 84 89 -
Tests/JAVA/logger/src/main/java/com/db/logger/api/impl/logger/formatters/FlyweightLogMessage.java
r589 r590 3 3 import com.db.logger.api.LogMessage; 4 4 import com.db.logger.api.impl.logger.CircularBuffer; 5 import com.db.logger.api.impl.logger.MessageInfo; 6 7 import static com.google.common.base.Preconditions.checkArgument; 5 8 6 9 /** 10 * format/formatId/agumentsCount are mutable, so instance may be adjusted to different 11 * messages 12 * 7 13 * @author ruslan 8 14 * created 20.11.13 at 23:48 … … 10 16 public class FlyweightLogMessage extends AbstractLogBuilder implements LogMessage { 11 17 12 private String format; 13 private int formatId; 14 15 private int argumentsCount; 18 private MessageInfo messageInfo = null; 16 19 17 20 public FlyweightLogMessage( final CircularBuffer circularBuffer ) { … … 19 22 } 20 23 21 public void setup( final String format, 22 final int formatId, 23 final int argumentsCount ) { 24 this.format = format; 25 this.formatId = formatId; 26 this.argumentsCount = argumentsCount; 24 public FlyweightLogMessage setup( final MessageInfo messageInfo ) { 25 checkArgument( messageInfo != null, "messageInfo can't be null" ); 26 this.messageInfo = messageInfo; 27 return this; 27 28 } 28 29 29 30 public int formatId() { 30 return formatId;31 return messageInfo.formatId; 31 32 } 32 33 33 34 @Override 34 35 public String format() { 35 return format;36 return messageInfo.format; 36 37 } 37 38 38 39 @Override 39 40 public int argumentsCount() { 40 return argumentsCount;41 return messageInfo.argumentsCount; 41 42 } 42 43 -
Tests/JAVA/logger/src/main/java/com/db/logger/api/impl/logger/formatters/RawLogMessage.java
r589 r590 4 4 import com.db.logger.api.FluentLogBuilder; 5 5 import com.db.logger.api.impl.logger.CircularBuffer; 6 import com.db.logger.api.impl.logger.MessageInfo; 6 7 import com.db.logger.api.impl.logger.RecordHelper; 7 8 … … 9 10 import static com.db.logger.api.impl.logger.DemultiplexingSequencer.INVALID_INDEX; 10 11 import static com.db.logger.api.impl.logger.RecordHelper.RecordType.LOG_RECORD; 12 import static com.google.common.base.Preconditions.checkArgument; 11 13 import static com.google.common.base.Preconditions.checkState; 12 14 … … 22 24 private long position = INVALID_INDEX; 23 25 24 private finalString format;25 private finalint formatId;26 private String format; 27 private int formatId; 26 28 27 private finalint argumentsCount;29 private int argumentsCount; 28 30 29 public RawLogMessage( final String format, 30 final int formatId, 31 final int argumentsCount, 32 final CircularBuffer circularBuffer ) { 31 public RawLogMessage( final CircularBuffer circularBuffer ) { 33 32 this.buffer = circularBuffer; 34 this.format = format;33 } 35 34 36 this.formatId = formatId; 37 this.argumentsCount = argumentsCount; 35 public RawLogMessage setup( final MessageInfo messageInfo ) { 36 checkArgument( messageInfo != null, "messageInfo can't be null" ); 37 this.format = messageInfo.format; 38 this.formatId = messageInfo.formatId; 39 this.argumentsCount = messageInfo.argumentsCount; 40 return this; 41 } 42 43 public RawLogMessage start() { 44 checkState( argumentIndex == NOT_SET, "Submit first!" ); 45 position = buffer.claim( argumentsCount + 1 );//1 for header 46 checkState( position != INVALID_INDEX, "Can't claim position" ); 47 argumentIndex = 0; 48 return this; 38 49 } 39 50 … … 50 61 public int argumentsCount() { 51 62 return argumentsCount; 52 }53 54 public FluentLogBuilder start() {55 checkState( argumentIndex == NOT_SET, "Submit first!" );56 position = buffer.claim( argumentsCount + 1 );//1 for header57 checkState( position != INVALID_INDEX, "Can't claim position" );58 argumentIndex = 0;59 return this;60 63 } 61 64 -
Tests/JAVA/logger/src/main/java/com/db/logger/api/impl/logger/formatters/SimpleLogMessage.java
r589 r590 13 13 */ 14 14 @NotThreadSafe 15 public final class SimpleLogMessage implements LogMessage {15 public final class SimpleLogMessage extends AbstractLogBuilder implements LogMessage { 16 16 17 17 private final String format; … … 20 20 private final int argumentsCount; 21 21 22 private final AbstractLogBuilder builder;23 24 22 25 23 public SimpleLogMessage( final String format, … … 27 25 final int argumentsCount, 28 26 final CircularBuffer circularBuffer ) { 29 builder = new AbstractLogBuilder( circularBuffer ) { 30 @Override 31 protected int formatId() { 32 return formatId; 33 } 34 35 @Override 36 protected int argumentsCount() { 37 return argumentsCount; 38 } 39 }; 27 super( circularBuffer ); 40 28 this.format = format; 41 29 42 30 this.formatId = formatId; 43 31 this.argumentsCount = argumentsCount; 44 }45 46 @Override47 public FluentLogBuilder with( final double value ) {48 builder.start();49 return builder.with( value );50 }51 52 @Override53 public FluentLogBuilder with( final long value ) {54 builder.start();55 return builder.with( value );56 }57 58 @Override59 public void log() {60 builder.start();61 builder.log();62 32 } 63 33 -
Tests/JAVA/logger/src/main/java/com/db/logger/api/impl/logger/formatters/SimpleLogMessageExpanded.java
r589 r590 1 1 package com.db.logger.api.impl.logger.formatters; 2 2 3 import com.db.logger.api.FluentLogBuilder; 3 4 import com.db.logger.api.LogMessage; 4 import com.db.logger.api.FluentLogBuilder;5 5 import com.db.logger.api.impl.logger.CircularBuffer; 6 6 import com.db.logger.api.impl.logger.RecordHelper; 7 7 8 import static com.db.logger.api.impl.logger.formatters.AbstractLogBuilder.NOT_SET;9 8 import static com.db.logger.api.impl.logger.DemultiplexingSequencer.INVALID_INDEX; 10 9 import static com.db.logger.api.impl.logger.RecordHelper.RecordType.LOG_RECORD; 10 import static com.db.logger.api.impl.logger.formatters.AbstractLogBuilder.NOT_SET; 11 11 import static com.google.common.base.Preconditions.checkState; 12 12 … … 15 15 * created 20.11.13 at 23:48 16 16 */ 17 public final class RawLogMessageimplements LogMessage, FluentLogBuilder {17 public final class SimpleLogMessageExpanded implements LogMessage, FluentLogBuilder { 18 18 19 19 private final CircularBuffer buffer; … … 27 27 private final int argumentsCount; 28 28 29 public RawLogMessage( final String format,30 final int formatId,31 final int argumentsCount,32 final CircularBuffer circularBuffer ) {29 public SimpleLogMessageExpanded( final String format, 30 final int formatId, 31 final int argumentsCount, 32 final CircularBuffer circularBuffer ) { 33 33 this.buffer = circularBuffer; 34 34 this.format = format; … … 52 52 } 53 53 54 public FluentLogBuilder start() { 55 checkState( argumentIndex == NOT_SET, "Submit first!" ); 56 position = buffer.claim( argumentsCount + 1 );//1 for header 57 checkState( position != INVALID_INDEX, "Can't claim position" ); 58 argumentIndex = 0; 59 return this; 54 protected void ensureStarted() { 55 if( position == INVALID_INDEX ) { 56 position = buffer.claim( argumentsCount() + 1 );//1 for header 57 checkState( position != INVALID_INDEX, "Claim failed" ); 58 59 argumentIndex = 0; 60 } 60 61 } 61 62 … … 63 64 @Override 64 65 public FluentLogBuilder with( final long value ) { 65 checkState( position != INVALID_INDEX, "Not started");66 // ensureStarted(); 66 67 // checkState( 67 68 // argumentIndex < argumentsCount(), … … 81 82 @Override 82 83 public FluentLogBuilder with( final double value ) { 84 ensureStarted(); 83 85 return with( Double.doubleToLongBits( value ) ); 84 86 } … … 86 88 @Override 87 89 public void log() { 88 checkState( position != INVALID_INDEX, "Not started");90 // ensureStarted(); 89 91 try { 90 92 // checkState( -
Tests/JAVA/logger/src/main/java/com/db/logger/benchmarks/BufferWriteAndDrainBenchmark.java
r589 r590 99 99 @GenerateMicroBenchmark 100 100 @Group( "writeAndPayloadAndDummyDrain" ) 101 @ Threads( 3 )//actually it's (CORES-1)101 @GroupThreads( 3 )//actually it's (CORES-1) 102 102 public void writer( final ThreadState ts ) { 103 103 writeEntry( ts.id, ts.count ); … … 107 107 @GenerateMicroBenchmark 108 108 @Group( "writeAndPayloadAndDummyDrain" ) 109 @ Threads( 1 )109 @GroupThreads( 1 ) 110 110 public void dummyDrainer() { 111 111 //mostly we do not care about drain latency here, measure just to be aware of it … … 123 123 @GenerateMicroBenchmark 124 124 @Group( "writeAndPayloadAndDrainAndRead" ) 125 @ Threads( 3 ) //actually it's (CORES-1)125 @GroupThreads( 3 ) //actually it's (CORES-1) 126 126 public void writer2( final ThreadState ts ) { 127 127 writeEntry( ts.id, ts.count ); … … 131 131 @GenerateMicroBenchmark 132 132 @Group( "writeAndPayloadAndDrainAndRead" ) 133 @ Threads( 1 )133 @GroupThreads( 1 ) 134 134 public void readingDrainer() { 135 135 //mostly we do not care about drain latency here, measure just to be aware of it -
Tests/JAVA/logger/src/main/java/com/db/logger/benchmarks/ConsumingDrainer.java
r589 r590 36 36 final int formatId = formatId( header ); 37 37 final int argumentsCount = argumentsCount( header ); 38 39 buffer.put( pos, NOT_SET ); 38 40 for( int i = 1; i <= argumentsCount; i++ ) { 39 41 hole.consume( buffer.get( pos + i ) ); 40 42 buffer.put( pos + i, NOT_SET );//needs to reclaim all! 41 43 } 42 buffer.put( pos, NOT_SET ); 44 43 45 pos += argumentsCount; 44 46 } -
Tests/JAVA/logger/src/main/java/com/db/logger/benchmarks/FastLoggerWithoutWriteBenchmark.java
r589 r590 5 5 import java.util.concurrent.atomic.AtomicInteger; 6 6 7 import com.db.logger.api.FluentLogBuilder; 7 8 import com.db.logger.api.LogMessage; 8 import com.db.logger.api.FluentLogBuilder;9 9 import com.db.logger.api.impl.logger.*; 10 10 import com.db.logger.api.impl.logger.buffer.DirectAccessLongBuffer; 11 11 import com.db.logger.api.impl.logger.buffer.ILongsBuffer; 12 import com.db.logger.api.impl.logger.formatters.DummyLogBuilder; 12 13 import org.apache.log4j.BasicConfigurator; 13 14 import org.apache.log4j.Logger; … … 16 17 17 18 /** 18 * Be cnhmark of SimpleFastLoggerwith dummy writer: just in-memory byte buffer which19 * Benchmark of FastLoggerImpl with dummy writer: just in-memory byte buffer which 19 20 * is cleared on flush. So, no real IO involved, nut apart from it, all other parts 20 21 * benchmarked … … 26 27 @OutputTimeUnit( TimeUnit.NANOSECONDS ) 27 28 @State( Scope.Group ) 28 public class FastLoggerWith ThreadLocalLogMessageBenchmark {29 private static final Logger log = Logger.getLogger( FastLoggerWith ThreadLocalLogMessageBenchmark.class );29 public class FastLoggerWithoutWriteBenchmark { 30 private static final Logger log = Logger.getLogger( FastLoggerWithoutWriteBenchmark.class ); 30 31 public static final int LENGTH = Integer.getInteger( "length", 1 << 14 ); 31 32 public static final int CELLS_PER_RECORD = Integer.getInteger( "cells-per-record", 8 );//8longs = 1 cache line … … 44 45 public DemultiplexingSequencer sequencer; 45 46 46 public ThreadLocalFastLoggerlogger;47 public FastLoggerImpl logger; 47 48 48 49 @Setup … … 50 51 buffer = new DirectAccessLongBuffer( LENGTH, RecordHelper.NOT_SET ); 51 52 sequencer = new DemultiplexingSequencer( LENGTH ); 52 logger = new ThreadLocalFastLogger(53 logger = new FastLoggerImpl( 53 54 new ThreadFactory() { 54 55 @Override … … 77 78 @GenerateMicroBenchmark 78 79 @Group( "payload" ) 80 @GroupThreads( 3 )//to be consistent with others 79 81 public void payloadAlone() { 82 FluentLogBuilder logBuilder = DummyLogBuilder.INSTANCE.with( 5d ); 83 final int count = CELLS_PER_RECORD; 84 for( int i = 1; i < count; i++ ) { 85 logBuilder = logBuilder.with( ( long ) i ); 86 } 87 logBuilder.log(); 88 BlackHole.consumeCPU( WRITER_BACKOFF ); 89 } 90 91 @GenerateMicroBenchmark 92 @Group( "logSimpleAndPayload" ) 93 @GroupThreads( 3 ) 94 public void writeSimpleMessage( final ThreadStateSimple ts ) { 95 if( ts.simpleMessage == null ) { 96 ts.setup( this ); 97 } 98 FluentLogBuilder logBuilder = ts.simpleMessage.with( 5d ); 99 final int count = CELLS_PER_RECORD; 100 for( int i = 1; i < count; i++ ) { 101 logBuilder = logBuilder.with( ( long ) i ); 102 } 103 logBuilder.log(); 104 80 105 BlackHole.consumeCPU( WRITER_BACKOFF ); 81 106 } … … 83 108 /*=============================================================================*/ 84 109 @GenerateMicroBenchmark 85 @Group( "loggingAndPayload" ) 86 public void writeFormatted( final ThreadState ts ) { 87 if( ts.formatter == null ) { 110 @Group( "logTLAndPayload" ) 111 @GroupThreads( 3 ) 112 public void writeTLMessage( final ThreadStateTL ts ) { 113 if( ts.threadLocalMessage == null ) { 88 114 ts.setup( this ); 89 115 } 90 FluentLogBuilder logBuilder = ts.formatter.with( 5d ); 91 final int count = CELLS_PER_RECORD; 92 for( int i = 1; i < count; i++ ) { 93 logBuilder = logBuilder.with( ( long ) i ); 94 } 95 logBuilder.log(); 96 97 BlackHole.consumeCPU( WRITER_BACKOFF ); 98 } 116 FluentLogBuilder logBuilder = ts.threadLocalMessage.with( 5d ); 117 final int count = CELLS_PER_RECORD; 118 for( int i = 1; i < count; i++ ) { 119 logBuilder = logBuilder.with( ( long ) i ); 120 } 121 logBuilder.log(); 122 123 BlackHole.consumeCPU( WRITER_BACKOFF ); 124 } 125 126 /*=============================================================================*/ 127 @GenerateMicroBenchmark 128 @Group( "logAndPayload" ) 129 @GroupThreads( 3 ) 130 public void writeMessage( final ThreadState ts ) { 131 FluentLogBuilder logBuilder = logger.message( ts.messageFormat ) 132 .with( 5d ); 133 final int count = CELLS_PER_RECORD; 134 for( int i = 1; i < count; i++ ) { 135 logBuilder = logBuilder.with( ( long ) i ); 136 } 137 logBuilder.log(); 138 139 BlackHole.consumeCPU( WRITER_BACKOFF ); 140 } 141 142 // @GenerateMicroBenchmark 143 // @Group( "lookupMessageInfo" ) 144 // @GroupThreads( 3 ) 145 // public Object lookupMessageInfo( final ThreadState ts ) { 146 // return logger.lookupMessageInfo( ts.messageFormat ); 147 // } 99 148 100 149 @State( Scope.Thread ) … … 102 151 public final int id = ID_GENERATOR.incrementAndGet(); 103 152 104 public LogMessage formatter; 105 106 public void setup( final FastLoggerWithThreadLocalLogMessageBenchmark b ) { 107 formatter = b.logger.message( id + " %d %f %d %f %d %f %f %f" ); 153 public final String messageFormat; 154 155 public ThreadState() { 156 final StringBuilder sb = new StringBuilder(); 157 sb.append( id ); 158 for( int i = 0; i < CELLS_PER_RECORD; i++ ) { 159 sb.append( " %d" ); 160 } 161 messageFormat = sb.toString(); 162 } 163 } 164 165 @State( Scope.Thread ) 166 public static class ThreadStateSimple extends ThreadState { 167 168 public LogMessage simpleMessage; 169 170 public void setup( final FastLoggerWithoutWriteBenchmark b ) { 171 simpleMessage = b.logger.messageSimple( messageFormat ); 172 } 173 } 174 175 @State( Scope.Thread ) 176 public static class ThreadStateTL extends ThreadState { 177 178 public LogMessage threadLocalMessage; 179 180 public void setup( final FastLoggerWithoutWriteBenchmark b ) { 181 threadLocalMessage = b.logger.messageThreadLocal( messageFormat ); 108 182 } 109 183 } 110 184 111 185 public static void main( final String[] args ) throws Exception { 112 final FastLoggerWithThreadLocalLogMessageBenchmark benchmark = new FastLoggerWithThreadLocalLogMessageBenchmark();113 114 benchmark.setup();115 final int BATCH = 1000000;116 final ThreadState[] states = new ThreadState[3];117 for( int i = 0; i < states.length; i++ ) {118 final ThreadState state = new ThreadState();119 states[i] = state;120 final Thread thread = new Thread() {121 @Override122 public void run() {123 for( int turn = 0; ; turn += BATCH ) {124 for( int i = 0; i < BATCH; i++ ) {125 benchmark.writeFormatted( state );126 }127 log.info( "Thread " + state.id + ": " + turn );128 }129 }130 };131 thread.setDaemon( true );132 thread.start();133 }134 135 Thread.sleep( 30000 );136 benchmark.tearDown();186 // final FastLoggerWithoutWriteBenchmark benchmark = new FastLoggerWithoutWriteBenchmark(); 187 // 188 // benchmark.setup(); 189 // final int BATCH = 1000000; 190 // final ThreadStateSimple[] states = new ThreadStateSimple[3]; 191 // for( int i = 0; i < states.length; i++ ) { 192 // final ThreadStateSimple state = new ThreadStateSimple(); 193 // states[i] = state; 194 // final Thread thread = new Thread() { 195 // @Override 196 // public void run() { 197 // for( int turn = 0; ; turn += BATCH ) { 198 // for( int i = 0; i < BATCH; i++ ) { 199 // benchmark.writeFormatted( state ); 200 // } 201 // log.info( "Thread " + state.id + ": " + turn ); 202 // } 203 // } 204 // }; 205 // thread.setDaemon( true ); 206 // thread.start(); 207 // } 208 // 209 // Thread.sleep( 30000 ); 210 // benchmark.tearDown(); 137 211 } 138 212 -
Tests/JAVA/logger/src/main/java/com/db/logger/benchmarks/Log4j20Benchmark.java
r589 r590 67 67 @GenerateMicroBenchmark 68 68 @Group( "formatAndRead" ) 69 @ Threads( 3 ) //actually it's (CORES-1)69 @GroupThreads( 3 ) //actually it's (CORES-1) 70 70 public void writeFormatted( final ThreadState ts ) { 71 71 if( ts.logger == null ) { … … 86 86 @GenerateMicroBenchmark 87 87 @Group( "formatAndRead" ) 88 @ Threads( 1 )88 @GroupThreads( 1 ) 89 89 public void readingDrainer() { 90 90 try { -
Tests/JAVA/logger/src/main/java/com/db/logger/benchmarks/RawLogMessageWriteAndDrainBenchmark.java
r589 r590 67 67 @GenerateMicroBenchmark 68 68 @Group( "formatAndReadAndPayload" ) 69 @ Threads( 3 ) //actually it's (CORES-1)69 @GroupThreads( 3 ) //actually it's (CORES-1) 70 70 public void writeFormatted( final ThreadState ts ) { 71 71 if( ts.formatter == null ) { … … 85 85 @GenerateMicroBenchmark 86 86 @Group( "formatAndReadAndPayload" ) 87 @ Threads( 1 )87 @GroupThreads( 1 ) 88 88 public void readingDrainer() { 89 89 try { … … 103 103 public void setup( final RawLogMessageWriteAndDrainBenchmark b ) { 104 104 formatter = new RawLogMessage( 105 "",106 id,107 CELLS_PER_RECORD - 1,108 105 new CircularBuffer( b.sequencer, b.buffer, WAITING_STRATEGY ) 106 ).setup( 107 new MessageInfo( 108 "", 109 id, 110 CELLS_PER_RECORD - 1 111 ) 109 112 ); 110 113 } -
Tests/JAVA/logger/src/main/java/com/db/logger/benchmarks/SimpleLogMessageWriteAndDrainBenchmark.java
r589 r590 9 9 import com.db.logger.api.impl.logger.buffer.ILongsBuffer; 10 10 import com.db.logger.api.impl.logger.formatters.SimpleLogMessage; 11 import com.db.logger.api.impl.logger.formatters.SimpleLogMessageExpanded; 11 12 import org.openjdk.jmh.annotations.*; 12 13 import org.openjdk.jmh.logic.BlackHole; … … 67 68 @GenerateMicroBenchmark 68 69 @Group( "formatAndReadAndPayload" ) 69 @ Threads( 3 ) //actually it's (CORES-1)70 @GroupThreads( 3 ) //actually it's (CORES-1) 70 71 public void writeFormatted( final ThreadState ts ) { 71 72 if( ts.formatter == null ) { … … 84 85 @GenerateMicroBenchmark 85 86 @Group( "formatAndReadAndPayload" ) 86 @ Threads( 1 )87 @GroupThreads( 1 ) 87 88 public void readingDrainer() { 88 89 try { 89 90 sequencer.drainTo( readingConsumer ); 90 // BlackHole.consumeCPU( 100 );91 // BlackHole.consumeCPU( 20 ); 91 92 } catch( Throwable e ) { 92 93 e.printStackTrace(); … … 98 99 public final int id = ID_GENERATOR.incrementAndGet(); 99 100 100 public SimpleLogMessage formatter;101 public SimpleLogMessageExpanded formatter; 101 102 102 103 public void setup( final SimpleLogMessageWriteAndDrainBenchmark b ) { 103 formatter = new SimpleLogMessage (104 formatter = new SimpleLogMessageExpanded( 104 105 "", 105 106 id, -
Tests/JAVA/logger/src/main/java/com/db/logger/benchmarks/helpers/AtomicBenchmark.java
r589 r590 20 20 System.err.println( "payload=" + WRITER_BACKOFF ); 21 21 } 22 22 23 //TODO use Unsafe for paiding 23 24 public AtomicInteger counter; … … 48 49 @GenerateMicroBenchmark 49 50 @Group( "writeAlone" ) 50 @ Threads( 1 )51 @GroupThreads( 1 ) 51 52 public long writerSolo() { 52 //Nl reason to backoff since no contention in solo 53 // BlackHole.consumeCPU( WRITER_BACKOFF ); 53 BlackHole.consumeCPU( WRITER_BACKOFF ); 54 54 return counter.incrementAndGet(); 55 55 } … … 58 58 @GenerateMicroBenchmark 59 59 @Group( "write4AndPayload" ) 60 @ Threads( 4 )//actually it's (CORES)60 @GroupThreads( 4 )//actually it's (CORES) 61 61 public long writer4() { 62 62 BlackHole.consumeCPU( WRITER_BACKOFF ); … … 67 67 @GenerateMicroBenchmark 68 68 @Group( "write3Read1AndPayload" ) 69 @ Threads( 3 )//actually it's (CORES-1)69 @GroupThreads( 3 )//actually it's (CORES-1) 70 70 public long writer3() { 71 71 BlackHole.consumeCPU( WRITER_BACKOFF ); … … 75 75 @GenerateMicroBenchmark 76 76 @Group( "write3Read1AndPayload" ) 77 @ Threads( 1 )77 @GroupThreads( 1 ) 78 78 public long reader1() { 79 79 return counter.get(); … … 84 84 @GenerateMicroBenchmark 85 85 @Group( "write2Read2AndPayload" ) 86 @ Threads( 2 )86 @GroupThreads( 2 ) 87 87 public long writer2() { 88 88 BlackHole.consumeCPU( WRITER_BACKOFF ); … … 92 92 @GenerateMicroBenchmark 93 93 @Group( "write2Read2AndPayload" ) 94 @ Threads( 2 )94 @GroupThreads( 2 ) 95 95 public long reader2() { 96 96 return counter.get(); … … 100 100 @GenerateMicroBenchmark 101 101 @Group( "write1Read3AndPayload" ) 102 @ Threads( 1 )102 @GroupThreads( 1 ) 103 103 public long writer1() { 104 104 BlackHole.consumeCPU( WRITER_BACKOFF ); … … 108 108 @GenerateMicroBenchmark 109 109 @Group( "write1Read3AndPayload" ) 110 @ Threads( 3 )110 @GroupThreads( 3 ) 111 111 public long reader3() { 112 112 return counter.get(); -
Tests/JAVA/logger/src/main/java/com/db/logger/benchmarks/helpers/IOBenchmark.java
r589 r590 24 24 @OutputTimeUnit( TimeUnit.MICROSECONDS ) 25 25 @State( Scope.Benchmark ) 26 @Threads( 1 ) 26 27 public class IOBenchmark { 27 28 -
Tests/JAVA/logger/src/main/java/com/db/logger/benchmarks/helpers/SequencerBenchmark.java
r589 r590 74 74 @GenerateMicroBenchmark 75 75 @Group( "claim3AndPayloadAndDrain1Dummy" ) 76 @ Threads( 3 )//actually it's (CORES-1)76 @GroupThreads( 3 )//actually it's (CORES-1) 77 77 public void claimer( final ThreadState ts ) { 78 78 claimEntry( ts.id, ts.count ); … … 82 82 @GenerateMicroBenchmark 83 83 @Group( "claim3AndPayloadAndDrain1Dummy" ) 84 @ Threads( 1 )84 @GroupThreads( 1 ) 85 85 public void drainer() { 86 86 try { -
Tests/JAVA/logger/src/main/java/com/db/logger/benchmarks/helpers/ThreadLocalBenchmark.java
r589 r590 12 12 @BenchmarkMode( { Mode.AverageTime } ) 13 13 @OutputTimeUnit( TimeUnit.NANOSECONDS ) 14 @State( Scope. Group)14 @State( Scope.Benchmark ) 15 15 public class ThreadLocalBenchmark { 16 16 // public static final int WRITER_BACKOFF = Integer.getInteger( "writer-backoff", 0 ); -
Tests/JAVA/logger/src/main/java/com/db/logger/benchmarks/helpers/UnsafeAtomicBenchmark.java
r589 r590 55 55 } 56 56 57 /*=============================================================================*/58 @GenerateMicroBenchmark59 @Group( "payload" )60 public void backoffAlone() {61 BlackHole.consumeCPU( WRITER_BACKOFF );62 }63 64 /*=============================================================================*/65 @GenerateMicroBenchmark66 @Group( "writeAlone" )67 @Threads( 1 )68 public long writerSolo() {69 //Nl reason to backoff since no contention in solo70 return incrementAndGet();71 }72 73 57 public long incrementAndGet() { 74 58 for(; ; ) { … … 83 67 /*=============================================================================*/ 84 68 @GenerateMicroBenchmark 69 @Group( "payload" ) 70 public void backoffAlone() { 71 BlackHole.consumeCPU( WRITER_BACKOFF ); 72 } 73 74 /*=============================================================================*/ 75 @GenerateMicroBenchmark 76 @Group( "writeAlone" ) 77 @GroupThreads( 1 ) 78 public long writerSolo() { 79 BlackHole.consumeCPU( WRITER_BACKOFF ); 80 return incrementAndGet(); 81 } 82 83 /*=============================================================================*/ 84 @GenerateMicroBenchmark 85 85 @Group( "write4AndPayload" ) 86 @ Threads( 4 )//actually it's (CORES)86 @GroupThreads( 4 )//actually it's (CORES) 87 87 public long writer4() { 88 88 BlackHole.consumeCPU( WRITER_BACKOFF ); … … 93 93 @GenerateMicroBenchmark 94 94 @Group( "write3Read1AndPayload" ) 95 @ Threads( 3 )//actually it's (CORES-1)95 @GroupThreads( 3 )//actually it's (CORES-1) 96 96 public long writer3() { 97 97 BlackHole.consumeCPU( WRITER_BACKOFF ); … … 101 101 @GenerateMicroBenchmark 102 102 @Group( "write3Read1AndPayload" ) 103 @ Threads( 1 )103 @GroupThreads( 1 ) 104 104 public long reader1() { 105 105 return counter; … … 110 110 @GenerateMicroBenchmark 111 111 @Group( "write2Read2AndPayload" ) 112 @ Threads( 2 )112 @GroupThreads( 2 ) 113 113 public long writer2() { 114 114 BlackHole.consumeCPU( WRITER_BACKOFF ); … … 118 118 @GenerateMicroBenchmark 119 119 @Group( "write2Read2AndPayload" ) 120 @ Threads( 2 )120 @GroupThreads( 2 ) 121 121 public long reader2() { 122 122 return counter; … … 126 126 @GenerateMicroBenchmark 127 127 @Group( "write1Read3AndPayload" ) 128 @ Threads( 1 )128 @GroupThreads( 1 ) 129 129 public long writer1() { 130 130 BlackHole.consumeCPU( WRITER_BACKOFF ); … … 134 134 @GenerateMicroBenchmark 135 135 @Group( "write1Read3AndPayload" ) 136 @ Threads( 3 )136 @GroupThreads( 3 ) 137 137 public long reader3() { 138 138 return counter; -
Tests/JAVA/logger/src/main/java/com/db/logger/benchmarks/helpers/VolatileBenchmark.java
r589 r590 41 41 @GenerateMicroBenchmark 42 42 @Group( "writeAlone" ) 43 @ Threads( 1 )43 @GroupThreads( 1 ) 44 44 public void writerSolo() { 45 45 BlackHole.consumeCPU( WRITER_BACKOFF ); … … 50 50 @GenerateMicroBenchmark 51 51 @Group( "write4" ) 52 @ Threads( 4 )//actually it's (CORES)52 @GroupThreads( 4 )//actually it's (CORES) 53 53 public void writer4() { 54 54 BlackHole.consumeCPU( WRITER_BACKOFF ); … … 59 59 @GenerateMicroBenchmark 60 60 @Group( "writeRead31" ) 61 @ Threads( 3 )//actually it's (CORES-1)61 @GroupThreads( 3 )//actually it's (CORES-1) 62 62 public void writer3() { 63 63 BlackHole.consumeCPU( WRITER_BACKOFF ); … … 67 67 @GenerateMicroBenchmark 68 68 @Group( "writeRead31" ) 69 @ Threads( 1 )69 @GroupThreads( 1 ) 70 70 public long reader1() { 71 71 return counter; … … 76 76 @GenerateMicroBenchmark 77 77 @Group( "writeRead22" ) 78 @ Threads( 2 )78 @GroupThreads( 2 ) 79 79 public void writer2() { 80 80 BlackHole.consumeCPU( WRITER_BACKOFF ); … … 84 84 @GenerateMicroBenchmark 85 85 @Group( "writeRead22" ) 86 @ Threads( 2 )86 @GroupThreads( 2 ) 87 87 public long reader2() { 88 88 return counter; … … 92 92 @GenerateMicroBenchmark 93 93 @Group( "writeRead13" ) 94 @ Threads( 1 )94 @GroupThreads( 1 ) 95 95 public void writer1() { 96 96 BlackHole.consumeCPU( WRITER_BACKOFF ); … … 100 100 @GenerateMicroBenchmark 101 101 @Group( "writeRead13" ) 102 @ Threads( 3 )102 @GroupThreads( 3 ) 103 103 public long reader3() { 104 104 return counter;
Note: See TracChangeset
for help on using the changeset viewer.