Changeset 582 for Tests


Ignore:
Timestamp:
12/03/13 05:39:28 (8 years ago)
Author:
BegemoT
Message:
 
Location:
Tests/JAVA/logger
Files:
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • Tests/JAVA/logger/logger.iml

    r581 r582  
    77      <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> 
    88      <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       <sourceFolder url="file://$MODULE_DIR$/target/generated-sources/annotations" isTestSource="false" /> 
    11       <excludeFolder url="file://$MODULE_DIR$/target/classes" /> 
    12       <excludeFolder url="file://$MODULE_DIR$/target/maven-archiver" /> 
    13       <excludeFolder url="file://$MODULE_DIR$/target/maven-status" /> 
    14       <excludeFolder url="file://$MODULE_DIR$/target/test-classes" /> 
     9      <excludeFolder url="file://$MODULE_DIR$/target" /> 
    1510    </content> 
    1611    <orderEntry type="inheritedJdk" /> 
     
    2823    <orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.0-beta9" level="project" /> 
    2924    <orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-core:2.0-beta9" level="project" /> 
    30     <orderEntry type="library" name="Maven: commons-cli:commons-cli:1.2" level="project" /> 
    31     <orderEntry type="library" name="Maven: org.apache.commons:commons-exec:1.1" level="project" /> 
    32     <orderEntry type="library" name="Maven: org.apache.commons:commons-math:2.1" level="project" /> 
    3325    <orderEntry type="library" name="Maven: com.google.guava:guava:15.0" level="project" /> 
    3426    <orderEntry type="library" name="Maven: org.springframework:spring-core:3.0.5.RELEASE" level="project" /> 
     
    3628    <orderEntry type="library" name="Maven: org.springframework:spring-beans:3.0.5.RELEASE" level="project" /> 
    3729    <orderEntry type="library" name="Maven: net.jcip:jcip-annotations:1.0" level="project" /> 
    38     <orderEntry type="library" name="Maven: com.googlecode.disruptor:disruptor:2.10" level="project" /> 
     30    <orderEntry type="library" name="Maven: com.lmax:disruptor:3.2.0" level="project" /> 
    3931    <orderEntry type="library" name="Maven: net.java.dev.jna:jna:3.4.0" level="project" /> 
    4032    <orderEntry type="library" name="Maven: org.affinity:affinity:0.1.1-SNAPSHOT" level="project" /> 
  • Tests/JAVA/logger/pom.xml

    r581 r582  
    119119 
    120120 
     121<!-- 
    121122        <dependency> 
    122123            <groupId>commons-cli</groupId> 
     
    134135            <version>2.1</version> 
    135136        </dependency> 
     137--> 
    136138 
    137139        <dependency> 
     
    166168 
    167169        <dependency> 
    168             <groupId>com.googlecode.disruptor</groupId> 
     170            <groupId>com.lmax</groupId> 
    169171            <artifactId>disruptor</artifactId> 
    170             <version>2.10</version> 
     172            <version>3.2.0</version> 
    171173        </dependency> 
    172174 
  • Tests/JAVA/logger/src/main/java/com/db/logger/benchmarks/BufferWriteAndDrainBenchmark.java

    r581 r582  
    1919@State( Scope.Group ) 
    2020public class BufferWriteAndDrainBenchmark { 
    21         public static final int LENGTH = Integer.getInteger( "length", 1 << 14 ); 
     21        public static final int LENGTH_POW = Integer.getInteger( "length-pow", 14 ); 
    2222        public static final int CELLS_PER_RECORD = Integer.getInteger( "cells-per-record", 8 );//8longs = 1 cache line 
    2323        public static final int WRITER_BACKOFF = Integer.getInteger( "writer-backoff", 20 ); 
    2424 
    25         public static final WaitingStrategy WAITING_STRATEGY = new WaitingStrategy.LimitedSpinning( 1024 ); 
     25        public static final WaitingStrategy WAITING_STRATEGY = new WaitingStrategy.LimitedSpinning( 4048 ); 
    2626 
    2727        public static final AtomicInteger ID_GENERATOR = new AtomicInteger( 1 ); 
     
    3434                } 
    3535        }; 
    36         static{ 
    37                 System.out.printf( "len=%d, record=%d, backoff=%d\n", LENGTH, CELLS_PER_RECORD, WRITER_BACKOFF ); 
     36 
     37        static { 
     38                System.out.printf( "len=2^%d, record=%d, backoff=%d\n", LENGTH_POW, CELLS_PER_RECORD, WRITER_BACKOFF ); 
    3839        } 
    3940 
     
    4546        @Setup 
    4647        public void setup() { 
    47                 buffer = new DirectAccessLongBuffer( LENGTH ); 
    48                 sequencer = new DemultiplexingSequencer( LENGTH ); 
     48                final int length = 1 << LENGTH_POW; 
     49                buffer = new DirectAccessLongBuffer( length ); 
     50                sequencer = new DemultiplexingSequencer( length ); 
    4951 
    5052                DRAIN_AND_READ = new DemultiplexingSequencer.Drainer() { 
     
    104106        @Threads( 1 ) 
    105107        public void dummyDrainer() { 
     108                //mostly we do not care about drain latency here, measure just to be aware of it 
    106109                try { 
    107110                        sequencer.drainTo( DRAIN_DUMMY ); 
    108                         BlackHole.consumeCPU( 100 ); 
     111//                      BlackHole.consumeCPU( 100 ); 
    109112                } catch( Throwable e ) { 
    110113                        e.printStackTrace(); 
     
    127130        @Threads( 1 ) 
    128131        public void readingDrainer() { 
     132                //mostly we do not care about drain latency here, measure just to be aware of it 
    129133                try { 
    130134                        sequencer.drainTo( DRAIN_AND_READ ); 
    131                         BlackHole.consumeCPU( 100 ); 
     135//                      BlackHole.consumeCPU( 100 ); 
    132136                } catch( Throwable e ) { 
    133137                        e.printStackTrace(); 
     
    139143        private void writeEntry( final int writerId, 
    140144                                 final int cellsCount ) { 
    141                 //TODO RC major: it needs to be timeout here, or benchmark will fail sometimes 
    142145                final long position = sequencer.claim( cellsCount, WAITING_STRATEGY ); 
    143146                if( position < 0 ) { 
     147                        System.err.println( "Timeout" ); 
    144148                        return; 
    145149                } 
  • Tests/JAVA/logger/src/main/java/com/db/logger/benchmarks/IOBenchmark.java

    r581 r582  
    1313 * and rely on BufferedStream in case of IO, or on manually-implemented ByteBuffer 
    1414 * buffering in case of NIO (while buffer size is -Dbuffer-size, default 2^14) 
     15 * <p/> 
     16 * I use single thread and re-create file on each benchmark iteration 
     17 * <p/> 
     18 * "ops" == "bytes", so ops/us -> bytes per microseconds 
    1519 * 
    16  * I use single thread and re-create file on each benchmark iteration 
    17  * 
    18  * "ops" == "bytes", so ops/us -> bytes per microseconds 
    1920 * @author cherrus 
    2021 *         created 11/23/13 at 2:04 PM 
  • Tests/JAVA/logger/src/main/java/com/db/logger/benchmarks/Log4j20Benchmark.java

    r581 r582  
    44import java.util.concurrent.atomic.AtomicInteger; 
    55 
    6 import com.db.logger.api.impl.logger.*; 
     6import com.db.logger.api.impl.logger.DemultiplexingSequencer; 
     7import com.db.logger.api.impl.logger.MessageFormatterImpl; 
     8import com.db.logger.api.impl.logger.WaitingStrategy; 
    79import com.db.logger.api.impl.logger.buffer.DirectAccessLongBuffer; 
    810import com.db.logger.api.impl.logger.buffer.ILongsBuffer; 
     11import org.apache.logging.log4j.*; 
     12import org.apache.logging.log4j.core.async.AsyncLogger; 
     13import org.apache.logging.log4j.core.async.AsyncLoggerContext; 
     14import org.apache.logging.log4j.core.config.Configuration; 
     15import org.apache.logging.log4j.core.config.DefaultConfiguration; 
     16import org.apache.logging.log4j.core.config.LoggerConfig; 
     17import org.apache.logging.log4j.core.helpers.ClockFactory; 
     18import org.apache.logging.log4j.core.helpers.CoarseCachedClock; 
     19import org.apache.logging.log4j.message.MessageFactory; 
     20import org.apache.logging.log4j.message.StringFormatterMessageFactory; 
    921import org.openjdk.jmh.annotations.*; 
     22import org.openjdk.jmh.annotations.Level; 
    1023import org.openjdk.jmh.logic.BlackHole; 
    1124 
    1225import static com.db.logger.api.impl.logger.RecordHelper.*; 
    13 import static com.db.logger.api.impl.logger.WaitingStrategy.SPINNING; 
    1426 
    1527/** 
     
    2032@OutputTimeUnit( TimeUnit.NANOSECONDS ) 
    2133@State( Scope.Group ) 
    22 public class FormatterWriteAndDrainBenchmark { 
     34public class Log4j20Benchmark { 
    2335        public static final int LENGTH = Integer.getInteger( "length", 1 << 14 ); 
    2436        public static final int CELLS_PER_RECORD = Integer.getInteger( "cells-per-record", 8 );//8longs = 1 cache line 
    2537        public static final int WRITER_BACKOFF = Integer.getInteger( "writer-backoff", 20 ); 
    2638 
    27         public static final WaitingStrategy WAITING_STRATEGY = new WaitingStrategy.LimitedSpinning( 1024 ); 
    28  
    2939        public static final AtomicInteger ID_GENERATOR = new AtomicInteger( 1 ); 
    3040 
    31         public static final DemultiplexingSequencer.Drainer DRAIN_DUMMY = new DemultiplexingSequencer.Drainer() { 
    32                 @Override 
    33                 public int available( final long startSequence, 
    34                                       final long sentinelSequence ) { 
    35                         return ( int ) ( sentinelSequence - startSequence ); 
    36                 } 
    37         }; 
    3841 
    3942        static { 
     43                System.setProperty( 
     44                                ClockFactory.PROPERTY_NAME, 
     45                                CoarseCachedClock.class.getName() 
     46                ); 
    4047                System.out.printf( "len=%d, record=%d, backoff=%d\n", LENGTH, CELLS_PER_RECORD, WRITER_BACKOFF ); 
    4148        } 
    4249 
    43         public ILongsBuffer buffer; 
    44         public DemultiplexingSequencer sequencer; 
    4550 
    46         public DemultiplexingSequencer.Drainer DRAIN_AND_READ; 
     51        public AsyncLoggerContext loggerContext; 
     52 
    4753 
    4854        @Setup 
    4955        public void setup() { 
    50                 buffer = new DirectAccessLongBuffer( LENGTH ); 
    51                 sequencer = new DemultiplexingSequencer( LENGTH ); 
     56                loggerContext = new AsyncLoggerContext( "benchmark" ); 
    5257 
    53                 DRAIN_AND_READ = new ConsumingDrainer(); 
     58 
    5459        } 
    5560 
     
    7681        @Threads( 3 ) //actually it's (CORES-1) 
    7782        public void writeFormatted( final ThreadState ts ) { 
    78                 if( ts.formatter == null ) { 
     83                if( ts.logger == null ) { 
    7984                        ts.setup( this ); 
    8085                } 
    81                 MessageFormatterImpl formatter = ts.formatter; 
    82                 formatter = formatter.start( WAITING_STRATEGY ); 
    83                 final int count = formatter.argumentsCount(); 
    84                 for( int i = 0; i < count; i++ ) { 
    85                         formatter = formatter.with( ( long ) i ); 
    86                 } 
    87                 formatter.submit(); 
     86                final AsyncLogger logger = ts.logger; 
     87                final Object[] arguments = new Object[CELLS_PER_RECORD - 1]; 
     88                logger.info( "", arguments ); 
     89//              final int count = formatter.argumentsCount(); 
     90//              for( int i = 0; i < count; i++ ) { 
     91//                      formatter = formatter.with( ( long ) i ); 
     92//              } 
     93//              formatter.submit(); 
    8894 
    8995                BlackHole.consumeCPU( WRITER_BACKOFF ); 
     
    95101        public void readingDrainer() { 
    96102                try { 
    97                         sequencer.drainTo( DRAIN_AND_READ ); 
     103//                      sequencer.drainTo( DRAIN_AND_READ ); 
    98104//                      BlackHole.consumeCPU( 100 ); 
    99105                } catch( Throwable e ) { 
     
    106112                public final int id = ID_GENERATOR.incrementAndGet(); 
    107113 
    108                 public MessageFormatterImpl formatter; 
     114                public AsyncLogger logger; 
    109115 
    110                 public void setup( final FormatterWriteAndDrainBenchmark b ) { 
    111                         formatter = new MessageFormatterImpl( 
     116                public void setup( final Log4j20Benchmark b ) { 
     117                        logger = new AsyncLogger( 
     118                                        b.loggerContext, 
    112119                                        "", 
    113                                         id, 
    114                                         CELLS_PER_RECORD - 1, 
    115                                         b.buffer, 
    116                                         b.sequencer 
     120                                        StringFormatterMessageFactory.INSTANCE 
    117121                        ); 
    118122                } 
     
    120124 
    121125        public static void main( final String[] args ) throws Exception { 
    122                 final FormatterWriteAndDrainBenchmark benchmark = new FormatterWriteAndDrainBenchmark(); 
     126                final Log4j20Benchmark benchmark = new Log4j20Benchmark(); 
    123127 
    124128                benchmark.setup(); 
     
    150154        } 
    151155 
    152         private class ConsumingDrainer implements DemultiplexingSequencer.Drainer { 
    153                 private static final int SPINS_PER_TURN = 256; 
    154  
    155                 private int spinsAvailable; 
    156                 private final BlackHole hole = new BlackHole(); 
    157  
    158                 @Override 
    159                 public int available( final long startSequence, 
    160                                       final long sentinelSequence ) { 
    161                         spinsAvailable = SPINS_PER_TURN; 
    162                         for( long pos = startSequence; pos < sentinelSequence; pos++ ) { 
    163                                 final long header = readHeader( pos ); 
    164                                 if( !isValidHeader( header ) ) { 
    165                                         return ( int ) ( pos - startSequence ); 
    166                                 } 
    167                                 final RecordHelper.RecordType type = type( header ); 
    168                                 final int formatId = formatId( header ); 
    169                                 final int argumentsCount = argumentsCount( header ); 
    170                                 for( int i = 1; i <= argumentsCount; i++ ) { 
    171                                         hole.consume( buffer.get( pos + i ) ); 
    172                                 } 
    173                                 buffer.put( pos, -1 ); 
    174                                 pos += argumentsCount; 
    175                         } 
    176                         return ( int ) ( sentinelSequence - startSequence ); 
    177                 } 
    178  
    179                 private long readHeader( final long pos ) { 
    180                         for(; spinsAvailable >= 0; spinsAvailable-- ) { 
    181                                 final long header = buffer.getVolatile( pos ); 
    182                                 if( isValidHeader( header ) ) { 
    183                                         return header; 
    184                                 } 
    185                         } 
    186                         return -1; 
    187                 } 
    188         } 
    189156} 
Note: See TracChangeset for help on using the changeset viewer.