Skip to content
This repository has been archived by the owner on Aug 23, 2020. It is now read-only.

Change: Count subtypes for pipeline threads #1681

Merged
merged 8 commits into from
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@
<version>${system-rules.version}</version>
<scope>test</scope>
</dependency>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't understand why this changed, but I'll ignore it this time
just be careful next time

On bigger PRs all those little changes are annoying
It also messes up hisotry

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
import com.iota.iri.utils.Converter;

import java.nio.ByteBuffer;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import com.iota.iri.utils.IotaUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -52,7 +54,12 @@
public class TransactionProcessingPipelineImpl implements TransactionProcessingPipeline {

private static final Logger log = LoggerFactory.getLogger(TransactionProcessingPipelineImpl.class);
private ExecutorService stagesThreadPool = Executors.newFixedThreadPool(6);
private ExecutorService stagesThreadPool = Executors.newFixedThreadPool(getNumberOfThreads());

/**
* List of stages that will be ignored when determining thread count
*/
private static final List IGNORED_STAGES = IotaUtils.createImmutableList(Stage.MULTIPLE, Stage.ABORT, Stage.FINISH);

// stages of the protocol protocol
private PreProcessStage preProcessStage;
Expand All @@ -69,6 +76,10 @@ public class TransactionProcessingPipelineImpl implements TransactionProcessingP
private BlockingQueue<ProcessingContext> broadcastStageQueue = new ArrayBlockingQueue<>(100);
private BlockingQueue<ProcessingContext> replyStageQueue = new ArrayBlockingQueue<>(100);

private int getNumberOfThreads() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last thing, usually when a method doesn't use the fields of the class I like to attach static to it
I used to think that the JIT optimizes it better but I don't think that's really true

However, I see advantages to it because:

  1. it can be used by public static methods
  2. when you review/maintain code you know immediately that this method can be reused/moved w/o fear
  3. when you change code you know immediately that the output of the method won't be affected due to a change to the state of the class

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this to a static final int now.

return Stage.values().length - IGNORED_STAGES.size();
}

/**
* Creates a {@link TransactionProcessingPipeline}.
*
Expand Down