Java Code Examples for org.apache.logging.log4j.core.util.Constants#ENABLE_DIRECT_ENCODERS
The following examples show how to use
org.apache.logging.log4j.core.util.Constants#ENABLE_DIRECT_ENCODERS .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DemoAppender.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@Override public void append(final LogEvent event) { if (Constants.ENABLE_DIRECT_ENCODERS) { getLayout().encode(event, this); drain(byteBuffer); } else { final byte[] binary = getLayout().toByteArray(event); consume(binary, 0, binary.length); } }
Example 2
Source File: JsonTemplateLayout.java From logging-log4j2 with Apache License 2.0 | 5 votes |
private static Supplier<Context> createContextSupplier( final Charset charset, final JsonWriter jsonWriter) { return () -> { final JsonWriter clonedJsonWriter = jsonWriter.clone(); final Encoder<StringBuilder> encoder = Constants.ENABLE_DIRECT_ENCODERS ? new LockingStringBuilderEncoder(charset) : null; return new Context(clonedJsonWriter, encoder); }; }
Example 3
Source File: AbstractOutputStreamAppender.java From logging-log4j2 with Apache License 2.0 | 5 votes |
private void tryAppend(final LogEvent event) { if (Constants.ENABLE_DIRECT_ENCODERS) { directEncodeEvent(event); } else { writeByteArrayToManager(event); } }
Example 4
Source File: AbstractStringLayout.java From logging-log4j2 with Apache License 2.0 | 5 votes |
/** * Builds a new layout. * @param aCharset the charset used to encode the header bytes, footer bytes and anything else that needs to be * converted from strings to bytes. * @param header the header bytes * @param footer the footer bytes */ protected AbstractStringLayout(final Charset aCharset, final byte[] header, final byte[] footer) { super(null, header, footer); this.headerSerializer = null; this.footerSerializer = null; this.charset = aCharset == null ? StandardCharsets.UTF_8 : aCharset; this.charsetName = this.charset.name(); useCustomEncoding = isPreJava8() && (StandardCharsets.ISO_8859_1.equals(aCharset) || StandardCharsets.US_ASCII.equals(aCharset)); textEncoder = Constants.ENABLE_DIRECT_ENCODERS ? new StringBuilderEncoder(charset) : null; }
Example 5
Source File: AbstractStringLayout.java From logging-log4j2 with Apache License 2.0 | 5 votes |
/** * Builds a new layout. * @param config the configuration * @param aCharset the charset used to encode the header bytes, footer bytes and anything else that needs to be * converted from strings to bytes. * @param headerSerializer the header bytes serializer * @param footerSerializer the footer bytes serializer */ protected AbstractStringLayout(final Configuration config, final Charset aCharset, final Serializer headerSerializer, final Serializer footerSerializer) { super(config, null, null); this.headerSerializer = headerSerializer; this.footerSerializer = footerSerializer; this.charset = aCharset == null ? StandardCharsets.UTF_8 : aCharset; this.charsetName = this.charset.name(); useCustomEncoding = isPreJava8() && (StandardCharsets.ISO_8859_1.equals(aCharset) || StandardCharsets.US_ASCII.equals(aCharset)); textEncoder = Constants.ENABLE_DIRECT_ENCODERS ? new StringBuilderEncoder(charset) : null; }
Example 6
Source File: ResponseTimeTest.java From logging-log4j2 with Apache License 2.0 | 4 votes |
public static void main(final String[] args) throws Exception { if (args.length < 2) { System.out.println("Please specify thread count, target throughput (msg/sec) " + "and logger library (Log4j1, Log4j2, Logback, JUL)"); return; } final int threadCount = Integer.parseInt(args[0]); final double loadMessagesPerSec = Double.parseDouble(args[1]); final String loggerLib = args.length > 2 ? args[2] : "Log4j2"; // print to console if ringbuffer is full System.setProperty("log4j2.AsyncQueueFullPolicy", PrintingAsyncQueueFullPolicy.class.getName()); System.setProperty("AsyncLogger.RingBufferSize", String.valueOf(256 * 1024)); //System.setProperty("Log4jContextSelector", AsyncLoggerContextSelector.class.getName()); //System.setProperty("log4j.configurationFile", "perf3PlainNoLoc.xml"); if (System.getProperty("AsyncLogger.WaitStrategy") == null) { System.setProperty("AsyncLogger.WaitStrategy", "Yield"); } //for (Object key : System.getProperties().keySet()) { // System.out.println(key + "=" + System.getProperty((String) key)); //} // initialize the logger final String wrapper = loggerLib.startsWith("Run") ? loggerLib : "Run" + loggerLib; final String loggerWrapperClass = "org.apache.logging.log4j.core.async.perftest." + wrapper; final IPerfTestRunner logger = Loader.newCheckedInstanceOf(loggerWrapperClass, IPerfTestRunner.class); logger.log("Starting..."); // ensure initialized Thread.sleep(100); final int requiredProcessors = threadCount + 1 + 1; // producers + 1 consumer + 1 for OS final IdleStrategy idleStrategy = Runtime.getRuntime().availableProcessors() > requiredProcessors ? new NoOpIdleStrategy() : new YieldIdleStrategy(); System.out.printf("%s: %d threads, load is %,f msg/sec, using %s%n", loggerLib, threadCount, loadMessagesPerSec, idleStrategy.getClass().getSimpleName()); // Warmup: run as many iterations of 50,000 calls to logger.log as we can in 1 minute final long WARMUP_DURATION_MILLIS = TimeUnit.MINUTES.toMillis(1); final List<Histogram> warmupServiceTmHistograms = new ArrayList<>(threadCount); final List<Histogram> warmupResponseTmHistograms = new ArrayList<>(threadCount); final int WARMUP_COUNT = 50000 / threadCount; runLatencyTest(logger, WARMUP_DURATION_MILLIS, WARMUP_COUNT, loadMessagesPerSec, idleStrategy, warmupServiceTmHistograms, warmupResponseTmHistograms, threadCount); System.out.println("-----------------Warmup done. load=" + loadMessagesPerSec); if (!Constants.ENABLE_DIRECT_ENCODERS || !Constants.ENABLE_THREADLOCALS) { //System.gc(); //Thread.sleep(5000); } System.out.println("-----------------Starting measured run. load=" + loadMessagesPerSec); final long start = System.currentTimeMillis(); final List<Histogram> serviceTmHistograms = new ArrayList<>(threadCount); final List<Histogram> responseTmHistograms = new ArrayList<>(threadCount); PrintingAsyncQueueFullPolicy.ringbufferFull.set(0); // Actual test: run as many iterations of 1,000,000 calls to logger.log as we can in 4 minutes. final long TEST_DURATION_MILLIS = TimeUnit.MINUTES.toMillis(4); final int COUNT = (1000 * 1000) / threadCount; runLatencyTest(logger, TEST_DURATION_MILLIS, COUNT, loadMessagesPerSec, idleStrategy, serviceTmHistograms, responseTmHistograms, threadCount); logger.shutdown(); final long end = System.currentTimeMillis(); // ... and report the results final Histogram resultServiceTm = createResultHistogram(serviceTmHistograms, start, end); resultServiceTm.outputPercentileDistribution(System.out, 1000.0); writeToFile("s", resultServiceTm, (int) (loadMessagesPerSec / 1000), 1000.0); final Histogram resultResponseTm = createResultHistogram(responseTmHistograms, start, end); resultResponseTm.outputPercentileDistribution(System.out, 1000.0); writeToFile("r", resultResponseTm, (int) (loadMessagesPerSec / 1000), 1000.0); System.out.printf("%n%s: %d threads, load %,f msg/sec, ringbuffer full=%d%n", loggerLib, threadCount, loadMessagesPerSec, PrintingAsyncQueueFullPolicy.ringbufferFull.get()); System.out.println("Test duration: " + (end - start) / 1000.0 + " seconds"); }