SEBSERV-445 better ping batch strategy?

This commit is contained in:
anhefti 2023-05-31 09:12:46 +02:00
parent 9708d8610b
commit 6ccf74f9c1
2 changed files with 19 additions and 10 deletions

View file

@ -378,9 +378,9 @@ public class ExamSessionServiceImpl implements ExamSessionService {
@Override @Override
public ClientConnectionDataInternal getConnectionDataInternal(final String connectionToken) { public ClientConnectionDataInternal getConnectionDataInternal(final String connectionToken) {
//synchronized (ExamSessionCacheService.CLIENT_CONNECTION_CREATION_LOCK) { synchronized (ExamSessionCacheService.CLIENT_CONNECTION_CREATION_LOCK) {
return this.examSessionCacheService.getClientConnection(connectionToken); return this.examSessionCacheService.getClientConnection(connectionToken);
//} }
} }
@Override @Override

View file

@ -8,8 +8,9 @@
package ch.ethz.seb.sebserver.webservice.servicelayer.session.impl; package ch.ethz.seb.sebserver.webservice.servicelayer.session.impl;
import java.util.HashMap; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.ehcache.impl.internal.concurrent.ConcurrentHashMap; import org.ehcache.impl.internal.concurrent.ConcurrentHashMap;
@ -45,7 +46,7 @@ public class SEBClientPingService {
} }
@Scheduled( @Scheduled(
fixedDelayString = "${sebserver.webservice.api.exam.session.ping.batch.interval:500}", fixedDelayString = "${sebserver.webservice.api.exam.session.ping.batch.interval:100}",
initialDelay = 1000) initialDelay = 1000)
public void processPings() { public void processPings() {
if (this.pings.isEmpty()) { if (this.pings.isEmpty()) {
@ -60,12 +61,16 @@ public class SEBClientPingService {
} }
try { try {
final Map<String, String> pp = new HashMap<>(this.pings); final Set<String> connections = new HashSet<>(this.pings.keySet());
this.pings.clear();
pp.entrySet() connections.stream().forEach(cid -> processPing(
.stream() cid,
.forEach(entry -> processPing(entry.getKey(), entry.getValue(), startTime)); this.pings.remove(cid),
Utils.getMillisecondsNow()));
// pp.entrySet()
// .stream()
// .forEach(entry -> processPing(entry.getKey(), entry.getValue(), startTime));
if (log.isTraceEnabled()) { if (log.isTraceEnabled()) {
log.trace("****** Processing {} SEB pings tuck: {}", Utils.getMillisecondsNow() - startTime); log.trace("****** Processing {} SEB pings tuck: {}", Utils.getMillisecondsNow() - startTime);
@ -83,6 +88,10 @@ public class SEBClientPingService {
final String connectionToken, final String connectionToken,
final String instructionConfirm) { final String instructionConfirm) {
if (connectionToken == null) {
return null;
}
if (instructionConfirm != null) { if (instructionConfirm != null) {
this.pings.put(connectionToken, instructionConfirm); this.pings.put(connectionToken, instructionConfirm);
} else if (!this.pings.containsKey(connectionToken)) { } else if (!this.pings.containsKey(connectionToken)) {