Skip to content

Commit

Permalink
post exports approx every 1.05 seconds, move timing check to BackendB…
Browse files Browse the repository at this point in the history
…roadcaster

 - twitch pubsub api limit is at most 1 per second
  • Loading branch information
avolny committed Feb 20, 2020
1 parent ed440d7 commit c528dc5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
13 changes: 10 additions & 3 deletions src/main/java/str_exporter/BackendBroadcaster.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public class BackendBroadcaster {

public static final Logger logger = LogManager.getLogger(BackendBroadcaster.class.getName());

private static final String EBS_URL = "https://localhost:8081";
// private static final String EBS_URL = "https://slaytherelics.xyz:8081";
// private static final String EBS_URL = "https://localhost:8081";
private static final String EBS_URL = "https://slaytherelics.xyz:8081";

private static final long CHECK_QUEUE_PERIOD_MILLIS = 100;
private static BackendBroadcaster instance = new BackendBroadcaster();
Expand Down Expand Up @@ -70,6 +70,12 @@ private void readQueue() {
queueLock.unlock();
if (!msg.isEmpty()) {
broadcastMessage(msg);

try {
Thread.sleep(950);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
Expand All @@ -94,7 +100,8 @@ private void broadcastMessage(String msg) {
while ((responseLine = br.readLine()) != null) {
response.append(responseLine.trim());
}
logger.info("response: " + response.toString());
logger.info(msg);
logger.info("broadcasted message, response: " + response.toString());

} catch (Exception e) {
e.printStackTrace();
Expand Down
34 changes: 17 additions & 17 deletions src/main/java/str_exporter/SlayTheRelicsExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class SlayTheRelicsExporter implements
private boolean checkNextUpdate = false;
private JSONMessageBuilder json_builder;

private static final long MAX_BROADCAST_PERIOD_MILLIS = 3 * 1000;
// private static final long MAX_BROADCAST_PERIOD_MILLIS = 250;
private static final long MAX_CHECK_PERIOD_MILLIS = 250;
public static SlayTheRelicsExporter instance = null;

Expand Down Expand Up @@ -115,22 +115,22 @@ private void broadcast() {
long end = System.nanoTime();

long start_equals = System.nanoTime();
if (System.currentTimeMillis() - lastBroadcast > MAX_BROADCAST_PERIOD_MILLIS || !json.equals(lastBroadcastJson)) {
long end_equals = System.nanoTime();
lastBroadcast = System.currentTimeMillis();
lastBroadcastJson = json;

long start_broadcast = System.nanoTime();
BackendBroadcaster.queueMessage(json);
long end_broadcast = System.nanoTime();
logger.info("broadcasting relics");
logger.info("json builder took " + (end - start) / 1e6 + " milliseconds");
logger.info("json string comparison took " + (end_equals - start_equals) / 1e6 + " milliseconds");
logger.info("adding to broadcast queue took " + (end_broadcast - start_broadcast) / 1e6 + " milliseconds");
logger.info(removeSecret(json));
} else {
// logger.info("Aborting rapidly repeated broadcast");
}
// if (System.currentTimeMillis() - lastBroadcast > MAX_BROADCAST_PERIOD_MILLIS || !json.equals(lastBroadcastJson)) {
long end_equals = System.nanoTime();
lastBroadcast = System.currentTimeMillis();
lastBroadcastJson = json;

long start_broadcast = System.nanoTime();
BackendBroadcaster.queueMessage(json);
long end_broadcast = System.nanoTime();
// logger.info("broadcasting relics");
logger.info("json builder took " + (end - start) / 1e6 + " milliseconds");
logger.info("json string comparison took " + (end_equals - start_equals) / 1e6 + " milliseconds");
logger.info("adding to broadcast queue took " + (end_broadcast - start_broadcast) / 1e6 + " milliseconds");
logger.info(removeSecret(json));
// } else {
//// logger.info("Aborting rapidly repeated broadcast");
// }
}

@Override
Expand Down

0 comments on commit c528dc5

Please sign in to comment.