-
Notifications
You must be signed in to change notification settings - Fork 370
Change: Count subtypes for pipeline threads #1681
Conversation
/** | ||
* List of stages that will be ignored when determining thread count | ||
*/ | ||
private static List<Stage> IGNORED_STAGES = new LinkedList<Stage>(){{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to
private static final List IGNORED_STAGES = IotaUtils.createImmutableList ...
You can optionally refactor createImmutableList
to ImmutableList
in a separate commit (only if you feel the name is too long, else you can leave it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DyrellC ?
private int getNumberOfThreads() { | ||
int threads = 0; | ||
for(Stage stage: Stage.values()) { | ||
if(!IGNORED_STAGES.contains(stage)){ | ||
threads += 1; | ||
} | ||
} | ||
return threads; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could have done it in a one liner:
return Stages.values().length - IGNORED_STAGES.size()
The above should also run faster (not that it matters much here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, the reason I feel this is important is because any extra line of code is one more line for the maintainer to read
Since code is written once but read many times, these little changes throughout the codebase may save lots of time later on.
@@ -69,6 +76,10 @@ | |||
private BlockingQueue<ProcessingContext> broadcastStageQueue = new ArrayBlockingQueue<>(100); | |||
private BlockingQueue<ProcessingContext> replyStageQueue = new ArrayBlockingQueue<>(100); | |||
|
|||
private int getNumberOfThreads() { |
There was a problem hiding this comment.
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:
- it can be used by public static methods
- when you review/maintain code you know immediately that this method can be reused/moved w/o fear
- 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
There was a problem hiding this comment.
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.
@@ -265,7 +265,6 @@ | |||
<version>${system-rules.version}</version> | |||
<scope>test</scope> | |||
</dependency> | |||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
* 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); | ||
private static final int NUMBER_OF_THREADS = Stage.values().length - IGNORED_STAGES.size(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
Description
Use reflections package to count the number of implementations of the
Stage
class to determine the number of threads that are needed for theTransactionProcessingPipeline
. It excludes theHashingStage
class as it is only used manually.Fixes #1680
Type of change
How Has This Been Tested?
Ensured count (excluding
HashingStage
) was equal to the number of threads that was previously manually entered.Checklist: