mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 02:30:08 -08:00
server: improved tourney threads naming, added max tourneys limit (max games / 10);
This commit is contained in:
parent
48c1bbdc01
commit
199345db07
4 changed files with 27 additions and 4 deletions
|
|
@ -119,11 +119,12 @@ public class DraftController {
|
||||||
private synchronized void checkStart() {
|
private synchronized void checkStart() {
|
||||||
if (!draft.isStarted() && allJoined()) {
|
if (!draft.isStarted() && allJoined()) {
|
||||||
draft.setStarted();
|
draft.setStarted();
|
||||||
managerFactory.threadExecutor().getCallExecutor().execute(this::startDraft);
|
managerFactory.threadExecutor().getTourneyExecutor().execute(this::startDraft);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startDraft() {
|
private void startDraft() {
|
||||||
|
Thread.currentThread().setName("TOURNEY DRAFT " + tableId);
|
||||||
for (final Entry<UUID, DraftSession> entry : draftSessions.entrySet()) {
|
for (final Entry<UUID, DraftSession> entry : draftSessions.entrySet()) {
|
||||||
if (!entry.getValue().init()) {
|
if (!entry.getValue().init()) {
|
||||||
logger.fatal("Unable to initialize client for playerId " + entry.getKey());
|
logger.fatal("Unable to initialize client for playerId " + entry.getKey());
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,11 @@ public interface ThreadExecutor {
|
||||||
*/
|
*/
|
||||||
ExecutorService getGameExecutor();
|
ExecutorService getGameExecutor();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tourney thread
|
||||||
|
*/
|
||||||
|
ExecutorService getTourneyExecutor();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper threads to execute async commands for game and server related tasks (example: process income command from a client)
|
* Helper threads to execute async commands for game and server related tasks (example: process income command from a client)
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -174,7 +174,7 @@ public class TournamentController {
|
||||||
|
|
||||||
private void checkStart() {
|
private void checkStart() {
|
||||||
if (!started && allJoined()) {
|
if (!started && allJoined()) {
|
||||||
managerFactory.threadExecutor().getCallExecutor().execute(this::startTournament);
|
managerFactory.threadExecutor().getTourneyExecutor().execute(this::startTournament);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -191,6 +191,7 @@ public class TournamentController {
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void startTournament() {
|
private synchronized void startTournament() {
|
||||||
|
Thread.currentThread().setName("TOURNEY " + tableId);
|
||||||
for (final TournamentSession tournamentSession : tournamentSessions.values()) {
|
for (final TournamentSession tournamentSession : tournamentSessions.values()) {
|
||||||
if (!tournamentSession.init()) {
|
if (!tournamentSession.init()) {
|
||||||
logger.fatal("Unable to initialize client userId: " + tournamentSession.userId + " tournamentId " + tournament.getId());
|
logger.fatal("Unable to initialize client userId: " + tournamentSession.userId + " tournamentId " + tournament.getId());
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,13 @@ public class ThreadExecutorImpl implements ThreadExecutor {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(ThreadExecutorImpl.class);
|
private static final Logger logger = Logger.getLogger(ThreadExecutorImpl.class);
|
||||||
|
|
||||||
|
// used for max tourney limit, but without new config setting
|
||||||
|
// example: server can have 100 games and 10 tourney at a time
|
||||||
|
private final int GAMES_PER_TOURNEY_RATIO = 100 / 10;
|
||||||
|
|
||||||
private final ExecutorService callExecutor; // shareable threads to run single task (example: save new game settings from a user, send chat message, etc)
|
private final ExecutorService callExecutor; // shareable threads to run single task (example: save new game settings from a user, send chat message, etc)
|
||||||
private final ExecutorService gameExecutor; // game threads to run long tasks, one per game (example: run game and wait user's feedback)
|
private final ExecutorService gameExecutor; // game threads to run long tasks, one per game (example: run game and wait user's feedback)
|
||||||
|
private final ExecutorService tourneyExecutor; // tourney threads (example: make draft, construction, build and run other game threads)
|
||||||
private final ScheduledExecutorService timeoutExecutor;
|
private final ScheduledExecutorService timeoutExecutor;
|
||||||
private final ScheduledExecutorService timeoutIdleExecutor;
|
private final ScheduledExecutorService timeoutIdleExecutor;
|
||||||
private final ScheduledExecutorService serverHealthExecutor;
|
private final ScheduledExecutorService serverHealthExecutor;
|
||||||
|
|
@ -44,15 +49,21 @@ public class ThreadExecutorImpl implements ThreadExecutor {
|
||||||
((ThreadPoolExecutor) gameExecutor).allowCoreThreadTimeOut(true);
|
((ThreadPoolExecutor) gameExecutor).allowCoreThreadTimeOut(true);
|
||||||
((ThreadPoolExecutor) gameExecutor).setThreadFactory(new XMageThreadFactory("GAME"));
|
((ThreadPoolExecutor) gameExecutor).setThreadFactory(new XMageThreadFactory("GAME"));
|
||||||
|
|
||||||
|
//tourney = Executors.newFixedThreadPool(config.getMaxGameThreads() / GAMES_PER_TOURNEY_RATIO);
|
||||||
|
tourneyExecutor = new FixedThreadPoolWithException(config.getMaxGameThreads() / GAMES_PER_TOURNEY_RATIO);
|
||||||
|
((ThreadPoolExecutor) tourneyExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
|
||||||
|
((ThreadPoolExecutor) tourneyExecutor).allowCoreThreadTimeOut(true);
|
||||||
|
((ThreadPoolExecutor) tourneyExecutor).setThreadFactory(new XMageThreadFactory("TOURNEY"));
|
||||||
|
|
||||||
timeoutExecutor = Executors.newScheduledThreadPool(4);
|
timeoutExecutor = Executors.newScheduledThreadPool(4);
|
||||||
((ThreadPoolExecutor) timeoutExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
|
((ThreadPoolExecutor) timeoutExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
|
||||||
((ThreadPoolExecutor) timeoutExecutor).allowCoreThreadTimeOut(true);
|
((ThreadPoolExecutor) timeoutExecutor).allowCoreThreadTimeOut(true);
|
||||||
((ThreadPoolExecutor) timeoutExecutor).setThreadFactory(new XMageThreadFactory("TIMEOUT"));
|
((ThreadPoolExecutor) timeoutExecutor).setThreadFactory(new XMageThreadFactory("XMAGE TIMEOUT"));
|
||||||
|
|
||||||
timeoutIdleExecutor = Executors.newScheduledThreadPool(4);
|
timeoutIdleExecutor = Executors.newScheduledThreadPool(4);
|
||||||
((ThreadPoolExecutor) timeoutIdleExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
|
((ThreadPoolExecutor) timeoutIdleExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
|
||||||
((ThreadPoolExecutor) timeoutIdleExecutor).allowCoreThreadTimeOut(true);
|
((ThreadPoolExecutor) timeoutIdleExecutor).allowCoreThreadTimeOut(true);
|
||||||
((ThreadPoolExecutor) timeoutIdleExecutor).setThreadFactory(new XMageThreadFactory("TIMEOUT_IDLE"));
|
((ThreadPoolExecutor) timeoutIdleExecutor).setThreadFactory(new XMageThreadFactory("XMAGE TIMEOUT_IDLE"));
|
||||||
|
|
||||||
serverHealthExecutor = Executors.newSingleThreadScheduledExecutor(new XMageThreadFactory("HEALTH"));
|
serverHealthExecutor = Executors.newSingleThreadScheduledExecutor(new XMageThreadFactory("HEALTH"));
|
||||||
}
|
}
|
||||||
|
|
@ -109,6 +120,11 @@ public class ThreadExecutorImpl implements ThreadExecutor {
|
||||||
return callExecutor;
|
return callExecutor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ExecutorService getTourneyExecutor() {
|
||||||
|
return tourneyExecutor;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ExecutorService getGameExecutor() {
|
public ExecutorService getGameExecutor() {
|
||||||
return gameExecutor;
|
return gameExecutor;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue