Skip to content
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

Avoid environment lookups and value conversions on hot paths #232

Merged
merged 1 commit into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class DaemonClientConnection implements Closeable {
private final Thread receiver;
private final AtomicBoolean running = new AtomicBoolean(true);
private final AtomicReference<Exception> exception = new AtomicReference<>();
private final long maxKeepAliveMs;
private final DaemonParameters parameters;

public DaemonClientConnection(DaemonConnection connection, DaemonInfo daemon,
Expand All @@ -64,6 +65,7 @@ public DaemonClientConnection(DaemonConnection connection, DaemonInfo daemon,
this.receiver = new Thread(this::doReceive);
this.receiver.start();
this.parameters = parameters;
this.maxKeepAliveMs = parameters.keepAlive().toMillis() * parameters.maxLostKeepAlive();
}

public void dispatch(Message message) throws DaemonException.ConnectException {
Expand Down Expand Up @@ -94,7 +96,6 @@ public void dispatch(Message message) throws DaemonException.ConnectException {
}

public List<Message> receive() throws ConnectException, StaleAddressException {
long maxKeepAliveMs = parameters.keepAlive().toMillis() * parameters.maxLostKeepAlive();
while (true) {
try {
final Message m = queue.poll(maxKeepAliveMs, TimeUnit.MILLISECONDS);
Expand Down
6 changes: 4 additions & 2 deletions daemon/src/main/java/org/mvndaemon/mvnd/daemon/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public class Server implements AutoCloseable, Runnable {
private final Lock stateLock = new ReentrantLock();
private final Condition condition = stateLock.newCondition();
private final DaemonMemoryStatus memoryStatus;
private final long keepAliveMs;

public Server() throws IOException {
// When spawning a new process, the child process is create within
Expand All @@ -107,6 +108,8 @@ public Server() throws IOException {
}
this.uid = Environment.MVND_UID.asString();
this.noDaemon = Environment.MVND_NO_DAEMON.asBoolean();
this.keepAliveMs = Environment.MVND_KEEP_ALIVE.asDuration().toMillis();

try {
cli = new DaemonMavenCli();
registry = new DaemonRegistry(Environment.MVND_REGISTRY.asPath());
Expand Down Expand Up @@ -424,7 +427,6 @@ private void cancelNow() {
private void handle(DaemonConnection connection, BuildRequest buildRequest) {
updateState(Busy);
try {
Duration keepAlive = Environment.MVND_KEEP_ALIVE.asDuration();

LOGGER.info("Executing request");

Expand All @@ -440,7 +442,7 @@ private void handle(DaemonConnection connection, BuildRequest buildRequest) {
while (true) {
Message m;
if (flushed) {
m = sendQueue.poll(keepAlive.toMillis(), TimeUnit.MILLISECONDS);
m = sendQueue.poll(keepAliveMs, TimeUnit.MILLISECONDS);
if (m == null) {
m = Message.KEEP_ALIVE_SINGLETON;
}
Expand Down