Class ExternalSampleSorter

  • All Implemented Interfaces:
    org.apache.jmeter.report.processor.SampleConsumer , org.apache.jmeter.report.processor.SampleProcessor , org.apache.jmeter.report.processor.SampleProducer

    
    public class ExternalSampleSorter
    extends AbstractSampleConsumer
                        

    R-way external sample sorter.

    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

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      boolean isParallelize()
      void sort(CsvFile inputFile, File outputFile, boolean writeHeader) Sort an input CSV file to an sorted output CSV file.
      void sort(SampleMetadata sampleMetadata, File inputFile, File outputFile, boolean writeHeader) Sort an input CSV file whose metadata structure is provided.
      void startConsuming() Start the sample consuming.
      void consume(Sample s, int channel) Consumes the specified sample ton the specified channel.
      void stopConsuming() Stops the consuming process.
      List<Sample> sort(List<Sample> samples)
      void mergeFiles(List<File> chunks, SampleMetadata metadata, SampleProducer producer)
      final boolean isRevertedSort()
      void setChunkSize(long chunkSize) Set the number of samples that will be stored in memory.
      final void setSampleComparator(SampleComparator sampleComparator) Set the sample comparator that will define sample ordering
      void setParallelize(boolean parallelize) Enabled parallel mode
      final void setRevertedSort(boolean revertedSort)
      • Methods inherited from class org.apache.jmeter.report.processor.AbstractSampleConsumer

        addSampleConsumer, getConsumedChannelCount, getConsumedMetadata, getName, getWorkingDirectory, produce, removeSampleConsumer, setChannelAttribute, setConsumedMetadata, setName, setProducedMetadata, setSampleConsumer, setSampleConsumers, setSampleContext, startProducing, stopProducing
      • Methods inherited from class org.apache.jmeter.report.processor.AbstractSampleProcessor

        getChannelAttribute, getSampleContext
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ExternalSampleSorter

        ExternalSampleSorter()
    • Method Detail

      • isParallelize

         boolean isParallelize()
        Returns:

        true when parallel mode is enabled, false otherwise

      • sort

         void sort(CsvFile inputFile, File outputFile, boolean writeHeader)

        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 be null)
        outputFile - The sorted destination CSV file (must not be null)
        writeHeader - Whether the CSV header should be written to the output CSV file
      • sort

         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 be null)
        inputFile - The input file to be sorted (must not be null)
        outputFile - The output sorted file (must not be null)
        writeHeader - Whether output CSV header should be written (based on provided sample metadata)
      • startConsuming

         void startConsuming()

        Start the sample consuming. This step is used by consumer to initialize their process.

      • consume

         void consume(Sample s, int channel)

        Consumes the specified sample ton the specified channel.

        Parameters:
        s - The sample to be consumed
        channel - The channel on which the sample is consumed
      • stopConsuming

         void stopConsuming()

        Stops the consuming process. No sample will be processed after this service has been called.

      • isRevertedSort

         final boolean isRevertedSort()
        Returns:

        flag, whether the order of the sort should be reverted

      • setChunkSize

         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.
      • setSampleComparator

         final void setSampleComparator(SampleComparator sampleComparator)

        Set the sample comparator that will define sample ordering

        Parameters:
        sampleComparator - comparator to define the ordering
      • setParallelize

         void setParallelize(boolean parallelize)

        Enabled parallel mode

        Parameters:
        parallelize - true to enable, false to disable
      • setRevertedSort

         final void setRevertedSort(boolean revertedSort)
        Parameters:
        revertedSort - flag, whether the order of the sort should be reverted.