mirror of
https://github.com/elastic/logstash.git
synced 2025-04-23 22:27:21 -04:00
Updates Netty's configuration of maxOrder to a previously proven value, if not already customised by the user.
Adds a step to the JvmOption parsing tool, which is used to compose the JVM options string to pass down to Logstash at startup.
The added step rework the parsed options to set the allocator max order -Dio.netty.allocator.maxOrder=11 so that the maximum pooled buffer is up to 16MB and not 4MB.
This option is added iff it's not yet specified by the user
(cherry picked from commit 52ce3ff8f6
)
Co-authored-by: Andrea Selva <selva.andre@gmail.com>
This commit is contained in:
parent
1cca6bcb2c
commit
2a5c4c906f
3 changed files with 60 additions and 4 deletions
|
@ -31,11 +31,11 @@ buildscript {
|
|||
}
|
||||
}
|
||||
|
||||
project.sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
project.targetCompatibility = JavaVersion.VERSION_1_8
|
||||
project.sourceCompatibility = JavaVersion.VERSION_11
|
||||
project.targetCompatibility = JavaVersion.VERSION_11
|
||||
|
||||
dependencies {
|
||||
testImplementation "junit:junit:4.12"
|
||||
testImplementation "junit:junit:4.13.1"
|
||||
}
|
||||
|
||||
javadoc {
|
||||
|
|
|
@ -32,6 +32,7 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
@ -180,7 +181,26 @@ public class JvmOptionsParser {
|
|||
// Set mandatory JVM options
|
||||
jvmOptionsContent.addAll(getMandatoryJvmOptions(javaMajorVersion));
|
||||
|
||||
System.out.println(String.join(" ", jvmOptionsContent));
|
||||
final Set<String> jvmFinalOptions = nettyMaxOrderDefaultTo11(jvmOptionsContent);
|
||||
|
||||
System.out.println(String.join(" ", jvmFinalOptions));
|
||||
}
|
||||
|
||||
/**
|
||||
* Inplace method that verifies if Netty's maxOrder option is already set, else configure it to have
|
||||
* the default value of 11.
|
||||
*
|
||||
* @param options the collection of options to examine.
|
||||
* @return the collection of input option eventually with Netty maxOrder added.
|
||||
* */
|
||||
private Set<String> nettyMaxOrderDefaultTo11(Set<String> options) {
|
||||
boolean maxOrderAlreadyContained = options.stream().anyMatch(s -> s.startsWith("-Dio.netty.allocator.maxOrder"));
|
||||
if (maxOrderAlreadyContained) {
|
||||
return options;
|
||||
}
|
||||
final Set<String> acc = new HashSet<>(options);
|
||||
acc.add("-Dio.netty.allocator.maxOrder=11");
|
||||
return acc;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,11 +8,15 @@ import org.junit.rules.TemporaryFolder;
|
|||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringReader;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
@ -123,6 +127,38 @@ public class JvmOptionsParserTest {
|
|||
assertEquals("anotherInvalidOption", res.getInvalidLines().get(4));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNettyMaxOrderRuleAppliesIfNotAlreadyDefinedExplicitlyByUser() throws IOException {
|
||||
File optionsFile = writeIntoTempOptionsFile(writer -> writer.println("-Dsome.other.netty.property=123"));
|
||||
|
||||
JvmOptionsParser.handleJvmOptions(new String[] {"/path/to/ls_home", optionsFile.toString()}, "-Dcli.opts=something");
|
||||
|
||||
// Verify
|
||||
final String output = outputStreamCaptor.toString();
|
||||
assertTrue("Existing properties other than Netty's maxOrder ar preserved", output.contains("-Dsome.other.netty.property=123"));
|
||||
assertTrue("Netty's maxOrder MUST be forcibly defined to the expected default", output.contains("-Dio.netty.allocator.maxOrder=11"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNettyMaxOrderRuleDoNotAppliesIfAlreadyDefinedExplicitlyByUser() throws IOException {
|
||||
File optionsFile = writeIntoTempOptionsFile(writer -> writer.println("-Dio.netty.allocator.maxOrder=10"));
|
||||
|
||||
JvmOptionsParser.handleJvmOptions(new String[] {"/path/to/ls_home", optionsFile.toString()}, "-Dcli.opts=something");
|
||||
|
||||
// Verify
|
||||
final String output = outputStreamCaptor.toString();
|
||||
assertTrue("Netty's maxOrder MUST be forcibly defined to the expected default", output.contains("-Dio.netty.allocator.maxOrder=10"));
|
||||
|
||||
}
|
||||
|
||||
private File writeIntoTempOptionsFile(Consumer<PrintWriter> writer) throws IOException {
|
||||
File optionsFile = temp.newFile("jvm.options");
|
||||
PrintWriter optionsWriter = new PrintWriter(new FileWriter(optionsFile));
|
||||
writer.accept(optionsWriter);
|
||||
optionsWriter.close();
|
||||
return optionsFile;
|
||||
}
|
||||
|
||||
private void verifyOptions(String message, String expected, JvmOptionsParser.ParseResult res) {
|
||||
assertEquals(message, expected, String.join(System.lineSeparator(), res.getJvmOptions()));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue