-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PAXLOGGING-311] Tests showing that there's no problem creating 10000…
… non-static loggers on 64M of heap in 1.11.x and 2.0.x
- Loading branch information
Showing
4 changed files
with
240 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
pax-logging-it/src/test/java/org/ops4j/pax/logging/it/Log4J1MemoryIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"); | ||
} | ||
} | ||
|
||
} |
79 changes: 79 additions & 0 deletions
79
pax-logging-it/src/test/java/org/ops4j/pax/logging/it/Log4J2MemoryIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"); | ||
} | ||
} | ||
|
||
} |
81 changes: 81 additions & 0 deletions
81
pax-logging-it/src/test/java/org/ops4j/pax/logging/it/LogbackMemoryIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"); | ||
} | ||
} | ||
|
||
} |