-
Notifications
You must be signed in to change notification settings - Fork 622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce separate thread pool for establishing Initiator connections #255
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0e05546
Introduce separate thread pool for establishing Initiator connections
chrjohn f5e050c
whitespace change
chrjohn f251421
fixed typo
chrjohn 2c4b2b5
Merge branch 'connection-timeout-254' of https://github.com/quickfix-…
chrjohn 8b635cd
- prevent NPE on Logon in Session when not specifying messageFactory in
chrjohn d55caff
- added possibility to specify number of reconnect threads via builder
chrjohn 7e1e534
minor formatting
chrjohn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,11 @@ | |
import java.util.Iterator; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.ThreadFactory; | ||
import java.util.concurrent.ThreadPoolExecutor; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
/** | ||
* Abstract base class for socket initiators. | ||
|
@@ -59,6 +64,8 @@ public abstract class AbstractSocketInitiator extends SessionConnector implement | |
|
||
protected final Logger log = LoggerFactory.getLogger(getClass()); | ||
private final Set<IoSessionInitiator> initiators = new HashSet<>(); | ||
private final ScheduledExecutorService scheduledReconnectExecutor; | ||
public static final String QFJ_RECONNECT_THREAD_PREFIX = "QFJ Reconnect Thread-"; | ||
|
||
protected AbstractSocketInitiator(Application application, | ||
MessageStoreFactory messageStoreFactory, SessionSettings settings, | ||
|
@@ -69,9 +76,27 @@ protected AbstractSocketInitiator(Application application, | |
|
||
protected AbstractSocketInitiator(SessionSettings settings, SessionFactory sessionFactory) | ||
throws ConfigError { | ||
this(settings, sessionFactory, 0); | ||
} | ||
|
||
protected AbstractSocketInitiator(Application application, | ||
MessageStoreFactory messageStoreFactory, SessionSettings settings, | ||
LogFactory logFactory, MessageFactory messageFactory, int numReconnectThreads) throws ConfigError { | ||
this(settings, new DefaultSessionFactory(application, messageStoreFactory, logFactory, | ||
messageFactory), numReconnectThreads); | ||
} | ||
|
||
protected AbstractSocketInitiator(SessionSettings settings, SessionFactory sessionFactory, int numReconnectThreads) | ||
throws ConfigError { | ||
super(settings, sessionFactory); | ||
IoBuffer.setAllocator(new SimpleBufferAllocator()); | ||
IoBuffer.setUseDirectBuffer(false); | ||
if (numReconnectThreads > 0) { | ||
scheduledReconnectExecutor = Executors.newScheduledThreadPool(numReconnectThreads, new QFScheduledReconnectThreadFactory()); | ||
((ThreadPoolExecutor) scheduledReconnectExecutor).setMaximumPoolSize(numReconnectThreads); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Setting |
||
} else { | ||
scheduledReconnectExecutor = null; | ||
} | ||
} | ||
|
||
protected void createSessionInitiators() | ||
|
@@ -145,9 +170,10 @@ && getSettings().isSetting(sessionID, Initiator.SETTING_PROXY_DOMAIN)) { | |
proxyPort = (int) settings.getLong(sessionID, Initiator.SETTING_PROXY_PORT); | ||
} | ||
|
||
ScheduledExecutorService scheduledExecutorService = (scheduledReconnectExecutor != null ? scheduledReconnectExecutor : getScheduledExecutorService()); | ||
final IoSessionInitiator ioSessionInitiator = new IoSessionInitiator(session, | ||
socketAddresses, localAddress, reconnectingIntervals, | ||
getScheduledExecutorService(), networkingOptions, | ||
scheduledExecutorService, networkingOptions, | ||
getEventHandlingStrategy(), getIoFilterChainBuilder(), sslEnabled, sslConfig, | ||
proxyType, proxyVersion, proxyHost, proxyPort, proxyUser, proxyPassword, proxyDomain, proxyWorkstation); | ||
|
||
|
@@ -309,4 +335,18 @@ public int getQueueSize() { | |
} | ||
|
||
protected abstract EventHandlingStrategy getEventHandlingStrategy(); | ||
|
||
|
||
private static class QFScheduledReconnectThreadFactory implements ThreadFactory { | ||
|
||
private static final AtomicInteger COUNTER = new AtomicInteger(1); | ||
|
||
@Override | ||
public Thread newThread(Runnable runnable) { | ||
Thread thread = new Thread(runnable, QFJ_RECONNECT_THREAD_PREFIX + COUNTER.getAndIncrement()); | ||
thread.setDaemon(true); | ||
return thread; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not directly related to this change, but we probably don't want to queue up timer tasks if they take too long for some reason.
quickfixj/quickfixj-core/src/main/java/quickfix/mina/initiator/IoSessionInitiator.java
Line 364 in e53d41b
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.
The
reconnectTasks
timed out after a maximum of 2000ms. That was the reason to have a bigger pool to service these requests, see #254 .What do you suggest to prevent piling up these tasks?
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.
Similar to
IoSessionInitiator
. As a rule of thumbscheduleWithFixedDelay
is better in majority of cases thanscheduleAtFixedRate
. It respects the delay, but it only reschedules when the tasks finishes - this does not allow bursts if for some reason task is slow.