Class ExternalSampleSorter
- All Implemented Interfaces:
SampleConsumer,SampleProcessor,SampleProducer
This SampleConsumer should be used to sort samples base on a
SampleComparator
Samples are sorted with the external sort algorithm. Thus, samples are not all stored in memory to be sorted. Instead, they are sorted by chunk in memory and then written to the disk before being merged at the end.
This sorter makes it possible to sort any number of samples with a fixed amount of memory. Hard disk will be used instead of RAM, at the cost of performance
When parallel mode is enabled and several CPU are available to the
JVM, this sorter uses multiple CPU to reduce sort time.
The parallel mode can be disabled if some sort of concurrency issue is
encountered.
As a last note, this SampleConsumer can be used as normal class with
the different sort() methods
It is important to set the chunkSize property according
to the available memory as the algorithm does not take care of memory
allocation (samples sizes are not predictable)
Meanwhile, it is equally important to set a SampleComparator to
define sample ordering
- Since:
- 3.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidConsumes the specified sample ton the specified channel.booleanfinal booleanvoidmergeFiles(List<File> chunks, SampleMetadata metadata, SampleProducer producer) voidsetChunkSize(long chunkSize) Set the number of samples that will be stored in memory.voidsetParallelize(boolean parallelize) Enabled parallel modefinal voidsetRevertedSort(boolean revertedSort) final voidsetSampleComparator(SampleComparator sampleComparator) Set the sample comparator that will define sample orderingvoidSort an input CSV file to an sorted output CSV file.voidsort(SampleMetadata sampleMetadata, File inputFile, File outputFile, boolean writeHeader) Sort an input CSV file whose metadata structure is provided.voidStart the sample consuming.voidStops the consuming process.Methods inherited from class org.apache.jmeter.report.processor.AbstractSampleConsumer
addSampleConsumer, getConsumedChannelCount, getConsumedMetadata, getConsumer, getDataFromContext, getName, getWorkingDirectory, produce, removeSampleConsumer, setChannelAttribute, setConsumedMetadata, setDataToContext, setName, setProducedMetadata, setSampleConsumer, setSampleConsumers, setSampleContext, startProducing, stopProducingMethods inherited from class org.apache.jmeter.report.processor.AbstractSampleProcessor
getChannelAttribute, getSampleContextMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.jmeter.report.processor.SampleProcessor
getChannelAttribute, getSampleContext
-
Constructor Details
-
ExternalSampleSorter
public ExternalSampleSorter() -
ExternalSampleSorter
-
-
Method Details
-
setChunkSize
public void setChunkSize(long chunkSize) Set the number of samples that will be stored in memory. This defines the number of samples that will be written in each chunk file before merging step as well.- Parameters:
chunkSize- The number of samples sorted in memory before they are written to disk. 5000 is the minimum and will be used if given chunkSize is less than 5000
-
setSampleComparator
Set the sample comparator that will define sample ordering- Parameters:
sampleComparator- comparator to define the ordering
-
setParallelize
public void setParallelize(boolean parallelize) Enabled parallel mode- Parameters:
parallelize-trueto enable,falseto disable
-
isParallelize
public boolean isParallelize()- Returns:
truewhen parallel mode is enabled,falseotherwise
-
sort
Sort an input CSV file to an sorted output CSV file.
The input CSV must have a header otherwise sorting will give unpredictable results
- Parameters:
inputFile- The CSV file to be sorted (must not benull)outputFile- The sorted destination CSV file (must not benull)writeHeader- Whether the CSV header should be written to the output CSV file
-
sort
public void sort(SampleMetadata sampleMetadata, File inputFile, File outputFile, boolean writeHeader) Sort an input CSV file whose metadata structure is provided. Use this method when input CSV file has no header : header information is then provided through the sampleMetadata parameter.- Parameters:
sampleMetadata- The CSV metadata : header information + separator (must not benull)inputFile- The input file to be sorted (must not benull)outputFile- The output sorted file (must not benull)writeHeader- Whether output CSV header should be written (based on provided sample metadata)
-
startConsuming
public void startConsuming()Description copied from interface:SampleConsumerStart the sample consuming. This step is used by consumer to initialize their process. -
consume
Description copied from interface:SampleConsumerConsumes the specified sample ton the specified channel.- Parameters:
s- The sample to be consumedchannel- The channel on which the sample is consumed
-
stopConsuming
public void stopConsuming()Description copied from interface:SampleConsumerStops the consuming process. No sample will be processed after this service has been called. -
sort
-
mergeFiles
-
isRevertedSort
public final boolean isRevertedSort()- Returns:
- flag, whether the order of the sort should be reverted
-
setRevertedSort
public final void setRevertedSort(boolean revertedSort) - Parameters:
revertedSort- flag, whether the order of the sort should be reverted.falseuses the order of the configuredSampleComparator
-