Open asfimport opened 6 years ago
@vlsi (migrated from Bugzilla): Allen, thanks for the suggestions, however could you please provide a reproducible test case so the performance fixes can be validated?
Do you have profiling results that quantify the impact of the issues you mention?
Allen (migrated from Bugzilla): (In reply to Vladimir Sitnikov from comment 1)
Allen, thanks for the suggestions, however could you please provide a reproducible test case so the performance fixes can be validated?
Do you have profiling results that quantify the impact of the issues you mention? Thanks for the reply, using simple textual descriptions to prove that performance improvement is really difficult.
I use the default condition generated csv result file as a test case file, which is greater than 900MB, and my local CPU is i7-6600U, memory is 16GB, window test command is : Measure-Command {.\jmeter.bat-g D: \case.csv -o D:\output01}.
you can observe the code is different, generate test report time will change.
In my optimization proposal, except that the modifications of the CSVSaveService and NormalizerSampleConsumer are more radical, other suggestions are based on the language features of the Java code itself. The results are the same, and the performance is definitely improved.
For the modifications of the CSVSaveService class and the NormalizerSampleConsumer class, I only tested the csv file generated from the default conditions. I believe that the code you write is so complicated and there must be a reason, so I can't be 100% certain that my changes cover all cases. For example, include special characters and so on.
So I just suggest that there is a csv file that can be judged to be generated by default. If it is a simple csv file, then use a simple test report generation program.
If you need a very comprehensive test basis to prove that the modifications of the CSVSaveService class and the NormalizerSampleConsumer class are harmless, I really don't have this. Because the csv test file I generated cannot cover all the scenarios and conditions.
@FSchumacher (migrated from Bugzilla): (In reply to Allen from comment 0)
Importance from high to low: 1. public class TransactionsPerSecondGraphConsumer extends AbstractOverTimeGraphConsumer @Override public Iterable<String> select(Sample sample) { String label = String.format(STATUS_SERIES_FORMAT, sample.getName(), sample.getSuccess() ? SUCCESS_SERIES_SUFFIX : FAILURE_SERIES_SUFFIX); return Arrays.asList(label); } String.format can replace to "" + "";
This would be possible and probably faster.
2. public class SyntheticResponseTimeDistributionGraphConsumer extends AbstractGraphConsumer { if(elapsedTime<=getSatisfiedThreshold()) { return Arrays.asList(SATISFIED_LABEL.format(new Object[] {Long.valueOf(getSatisfiedThreshold())})); } else if(elapsedTime <= getToleratedThreshold()) { return Arrays.asList(TOLERATED_LABEL.format(new Object[] {Long.valueOf(getSatisfiedThreshold()), Long.valueOf(getToleratedThreshold())})); } else { return Arrays.asList(UNTOLERATED_LABEL.format(new Object[] {Long.valueOf(getToleratedThreshold())})); } The same: String.format to slow.
String#format is slow, but simple concatenation doesn't help here, as the labels are used for localization.
We probably would need a pre-compiled String#format mechanism, that would be initialized ones and reused afterwards. Sadly, that is not possible with the standard implementation of String#format.
3. public final class CSVSaveService { public static String[] csvReadFile(BufferedReader infile, char delim) throws IOException { why not use like this: String str = infile.readLine(); if (str == null) { return new String[]{}; } return str.split("" + delim); the code: if ((ch == '\n' || ch == '\r') && state != ParserState.QUOTED) Consumes a lot of CPU time
This one is needed, as the CSV file may contain new lines inside of quoted text. If we remove it, we can not read in all of our self generated csv files.
4. public class NormalizerSampleConsumer extends AbstractSampleConsumer { public void consume(Sample s, int channel) {
I just return super.produce(s, 0);
5. public class SampleMetadata { private TreeMap<String, Integer> index = new TreeMap<>();
why not use private HashMap<String, Integer> index = new HashMap<>();
6. public static <T> T convert(Class<T> clazz, String value) throws ConvertException { why not just return like bellow:
f (clazz.isAssignableFrom(String.class)) { return (T) value; } if (clazz.isAssignableFrom(Long.class) || clazz.isAssignableFrom(long.class)) { return (T) Long.valueOf(value); } if (clazz.isAssignableFrom(Boolean.class) || clazz.isAssignableFrom(boolean.class)) { return (T) Boolean.valueOf(value); } if (clazz.isAssignableFrom(Integer.class) || clazz.isAssignableFrom(int.class)) { return (T) Integer.valueOf(value); } if (clazz.isAssignableFrom(Double.class) || clazz.isAssignableFrom(double.class)) { return (T) Double.valueOf(value); } if (clazz.isAssignableFrom(Float.class) || clazz.isAssignableFrom(float.class)) { return (T) Float.valueOf(value); } if (clazz.isAssignableFrom(Character.class) || clazz.isAssignableFrom(char.class)) { return (T) Character.valueOf(value.charAt(0)); } else { StringConverter<T> converter = Converters.getConverter(clazz); if (converter == null) { throw new ConvertException(value, clazz.getName()); } result = converter.convert(value); }
My performance can be improved by at least 50%
The original code may be considered for special situations, but the default generated report file, I have no difference between the test before and after the modification
Do you have transaction samplers in your csv sample files?
@vlsi (migrated from Bugzilla): The suggested fixes do not look like to result in "50% speedup with no drawbacks".
I agree SampleMetadata.index should be changed from TreeMap to HashMap, however it should not be that important though. The field type should be just Map interface, not the class type.
Regarding the other changes, I would like to see profiling results. I'm inclined to decline "performance" fixes unless there's justification.
So I just suggest that there is a csv file that can be judged to be generated by default. If it is a simple csv file, then use a simple test report generation program.
I agree, there should be a test CSV file that is used to benchmark report generator. However, I do not have such a file.
@FSchumacher (migrated from Bugzilla): Simple python script that generates a jtl file with 5 million lines which equals to about 460 MB.
Created attachment generate_tests.py: Script to generate a jtl file that could be used for performance testing
@FSchumacher (migrated from Bugzilla): Simple (maybe too simple) implementation of a pre-compiled version of String#format that can be used to replace the really simple variants that are used in the report generation process.
It is about 10 times faster than String#format, but slower than concatenation.
Benchmark Mode Cnt Score Error Units MyBenchmark.concatenate thrpt 5 69766343,254 ± 2020598,233 ops/s MyBenchmark.preCompiledFormatter thrpt 5 21432505,044 ± 563230,597 ops/s MyBenchmark.stringFormat thrpt 5 1665297,020 ± 34538,703 ops/s
Created attachment 0001-Use-pre-compiled-text-formatter-instead-of-String-fo.patch: Simple replacement for String#format
@FSchumacher (migrated from Bugzilla): A few more seconds can be gained by not recalculating data in the samples.
Created attachment 0002-Convert-data-eagerly-to-optimize-report-generation.patch: Eager initialization of fields in sample
@FSchumacher (migrated from Bugzilla): With the attached patches my laptop processes the test files in 1:18 instead of 1:58.
It should be noted, that report generation is single threaded. It might be interesting to see, if decoupling reading of csv and aggregating them into the different report classes into different threads might help.
@pmouawad (migrated from Bugzilla): (In reply to Felix Schumacher from comment 9)
With the attached patches my laptop processes the test files in 1:18 instead of 1:58.
Nice !
It should be noted, that report generation is single threaded. It might be interesting to see, if decoupling reading of csv and aggregating them into the different report classes into different threads might help.
Yes, maybe we should see which step is the most consuming. Isn't it initial sorting ?
@FSchumacher (migrated from Bugzilla): Date: Sun Jul 8 11:45:32 2018 New Revision: 1835351
URL: http://svn.apache.org/viewvc?rev=1835351&view=rev Log: Optimize performance of report generation.
Compute things that don't change, but get used often eagerly. Don't use String#format for simple concatenation, as it is really slow. Based on feedback by Allen (444104595 at qq.com)
https://github.com/apache/jmeter/issues/4790
Modified: jmeter/trunk/src/core/org/apache/jmeter/report/core/Sample.java jmeter/trunk/src/core/org/apache/jmeter/report/processor/graph/impl/SyntheticResponseTimeDistributionGraphConsumer.java jmeter/trunk/src/core/org/apache/jmeter/report/processor/graph/impl/TransactionsPerSecondGraphConsumer.java jmeter/trunk/xdocs/changes.xml
Allen (Bug 62426): Importance from high to low: 1. public class TransactionsPerSecondGraphConsumer extends AbstractOverTimeGraphConsumer @Override public Iterable<String> select(Sample sample) { String label = String.format(STATUS_SERIES_FORMAT, sample.getName(), sample.getSuccess() ? SUCCESS_SERIES_SUFFIX : FAILURE_SERIES_SUFFIX); return Arrays.asList(label); } String.format can replace to "" + "";
2. public class SyntheticResponseTimeDistributionGraphConsumer extends AbstractGraphConsumer { if(elapsedTime<=getSatisfiedThreshold()) { return Arrays.asList(SATISFIED_LABEL.format(new Object[] {Long.valueOf(getSatisfiedThreshold())})); } else if(elapsedTime <= getToleratedThreshold()) { return Arrays.asList(TOLERATED_LABEL.format(new Object[] {Long.valueOf(getSatisfiedThreshold()), Long.valueOf(getToleratedThreshold())})); } else { return Arrays.asList(UNTOLERATED_LABEL.format(new Object[] {Long.valueOf(getToleratedThreshold())})); } The same: String.format to slow.
3. public final class CSVSaveService { public static String[] csvReadFile(BufferedReader infile, char delim) throws IOException { why not use like this: String str = infile.readLine(); if (str == null) { return new String[]{}; } return str.split("" + delim); the code: if ((ch == '\n' || ch == '\r') && state != ParserState.QUOTED) Consumes a lot of CPU time
4. public class NormalizerSampleConsumer extends AbstractSampleConsumer { public void consume(Sample s, int channel) {
I just return super.produce(s, 0);
5. public class SampleMetadata { private TreeMap<String, Integer> index = new TreeMap<>();
why not use private HashMap<String, Integer> index = new HashMap<>();
6. public static <T> T convert(Class<T> clazz, String value) throws ConvertException { why not just return like bellow:
f (clazz.isAssignableFrom(String.class)) { return (T) value; } if (clazz.isAssignableFrom(Long.class) || clazz.isAssignableFrom(long.class)) { return (T) Long.valueOf(value); } if (clazz.isAssignableFrom(Boolean.class) || clazz.isAssignableFrom(boolean.class)) { return (T) Boolean.valueOf(value); } if (clazz.isAssignableFrom(Integer.class) || clazz.isAssignableFrom(int.class)) { return (T) Integer.valueOf(value); } if (clazz.isAssignableFrom(Double.class) || clazz.isAssignableFrom(double.class)) { return (T) Double.valueOf(value); } if (clazz.isAssignableFrom(Float.class) || clazz.isAssignableFrom(float.class)) { return (T) Float.valueOf(value); } if (clazz.isAssignableFrom(Character.class) || clazz.isAssignableFrom(char.class)) { return (T) Character.valueOf(value.charAt(0)); } else { StringConverter<T> converter = Converters.getConverter(clazz); if (converter == null) { throw new ConvertException(value, clazz.getName()); } result = converter.convert(value); }
My performance can be improved by at least 50%
The original code may be considered for special situations, but the default generated report file, I have no difference between the test before and after the modification
OS: All
Duplicates: