Skip to content

Commit

Permalink
[PAXLOGGING-311] Tests showing that there's no problem creating 10000…
Browse files Browse the repository at this point in the history
… non-static loggers on 64M of heap in 1.11.x and 2.0.x
  • Loading branch information
grgrzybek committed Mar 14, 2020
1 parent e9e0251 commit a67324f
Show file tree
Hide file tree
Showing 4 changed files with 240 additions and 0 deletions.
1 change: 1 addition & 0 deletions pax-logging-it/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<forkCount>1</forkCount>
<reuseForks>false</reuseForks>
<trimStackTrace>false</trimStackTrace>
<argLine>-Xmx64M -XX:+HeapDumpOnOutOfMemoryError</argLine>
</configuration>
<executions>
<execution>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.ops4j.pax.logging.it;

import java.io.IOException;
import java.util.UUID;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.ops4j.pax.exam.OptionUtils.combine;

@RunWith(PaxExam.class)
public class Log4J1MemoryIntegrationTest extends AbstractControlledIntegrationTestBase {

@Configuration
public Option[] configure() throws IOException {
return combine(
combine(baseConfigure(), defaultLoggingConfig()),

paxLoggingApi(),
paxLoggingLog4J1(),
configAdmin(),
eventAdmin()
);
}

@Test
public void memoryIssues() throws IOException {
LOG.info("Starting");
String[] loggerNames = new String[10_000];
for (int i = 0; i < 10_000; i++) {
loggerNames[i] = UUID.randomUUID().toString();
}
for (int i = 0; i < 1_000_000; i++) {
if (i % 10_000 == 0) {
LOG.info("iteration {}", i);
System.gc();
}
new MyClass(loggerNames[i % 10_000]).run();
}
LOG.info("Done");
}

private static class MyClass {
private Logger nonStaticLogger;

public MyClass(String name) {
this.nonStaticLogger = LoggerFactory.getLogger(name);
}

public void run() {
// running a method
nonStaticLogger.trace("Hello!");
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.ops4j.pax.logging.it;

import java.io.IOException;
import java.util.UUID;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.ops4j.pax.exam.OptionUtils.combine;

@RunWith(PaxExam.class)
public class Log4J2MemoryIntegrationTest extends AbstractControlledIntegrationTestBase {

@Configuration
public Option[] configure() throws IOException {
return combine(
combine(baseConfigure(), defaultLoggingConfig()),

paxLoggingApi(),
paxLoggingLog4J2(),
configAdmin(),
eventAdmin()
);
}

@Test
public void memoryIssues() throws IOException {
LOG.info("Starting");
String[] loggerNames = new String[10_000];
for (int i = 0; i < 10_000; i++) {
loggerNames[i] = UUID.randomUUID().toString();
}
for (int i = 0; i < 1_000_000; i++) {
if (i % 10_000 == 0) {
LOG.info("iteration {}", i);
System.gc();
}
new Log4J2MemoryIntegrationTest.MyClass(loggerNames[i % 10_000]).run();
}
LOG.info("Done");
}

private static class MyClass {
private Logger nonStaticLogger;

public MyClass(String name) {
this.nonStaticLogger = LoggerFactory.getLogger(name);
}

public void run() {
// running a method
nonStaticLogger.trace("Hello!");
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.ops4j.pax.logging.it;

import java.io.IOException;
import java.util.UUID;

import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.ops4j.pax.exam.OptionUtils.combine;

@RunWith(PaxExam.class)
public class LogbackMemoryIntegrationTest extends AbstractControlledIntegrationTestBase {

@Configuration
public Option[] configure() throws IOException {
return combine(
combine(baseConfigure(), defaultLoggingConfig()),

paxLoggingApi(),
paxLoggingLogback(),
configAdmin(),
eventAdmin()
);
}

@Test
// @Ignore("Logback in this scenario is broken beyond any repair.")
public void memoryIssues() throws IOException {
LOG.info("Starting");
String[] loggerNames = new String[10_000];
for (int i = 0; i < 10_000; i++) {
loggerNames[i] = UUID.randomUUID().toString();
}
for (int i = 0; i < 1_000_000; i++) {
if (i % 10_000 == 0) {
LOG.info("iteration {}", i);
System.gc();
}
new LogbackMemoryIntegrationTest.MyClass(loggerNames[i % 10_000]).run();
}
LOG.info("Done");
}

private static class MyClass {
private Logger nonStaticLogger;

public MyClass(String name) {
this.nonStaticLogger = LoggerFactory.getLogger(name);
}

public void run() {
// running a method
nonStaticLogger.trace("Hello!");
}
}

}

0 comments on commit a67324f

Please sign in to comment.