debug statistics (recording iteration lag)

This commit is contained in:
reusedname 2024-12-17 11:05:06 +05:00
parent 5bc8a6fdf9
commit 435cbbdb95
5 changed files with 43 additions and 0 deletions

View File

@ -88,6 +88,16 @@
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.10.0.pr1</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.2</version>
</dependency>
</dependencies>

View File

@ -39,6 +39,7 @@ import static java.util.concurrent.TimeUnit.SECONDS;
@Slf4j
public class SimplifiedLocalRecorder implements Recorder {
public static final Statistics STATS = new Statistics();
public static final boolean IGNORE_CACHE = true;
private final List<Model> models = Collections.synchronizedList(new ArrayList<>());

View File

@ -0,0 +1,21 @@
package ctbrec.recorder;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.apache.commons.collections.buffer.CircularFifoBuffer;
public class Statistics {
public ReadWriteLock statsLock = new ReentrantReadWriteLock();
public CircularFifoBuffer stats = new CircularFifoBuffer(100);
public void add(Object val) {
statsLock.writeLock().lock();
try {
stats.add(val);
} finally {
statsLock.writeLock().unlock();
}
}
}

View File

@ -14,6 +14,7 @@ import ctbrec.io.HttpClient;
import ctbrec.io.HttpConstants;
import ctbrec.io.HttpException;
import ctbrec.recorder.InvalidPlaylistException;
import ctbrec.recorder.SimplifiedLocalRecorder;
import ctbrec.recorder.download.AbstractDownload;
import ctbrec.recorder.download.HttpHeaderFactory;
import ctbrec.recorder.download.StreamSource;
@ -108,6 +109,7 @@ public abstract class AbstractHlsDownload extends AbstractDownload {
@Override
public AbstractHlsDownload call() throws Exception {
SimplifiedLocalRecorder.STATS.add(Duration.between(rescheduleTime, Instant.now()).toMillis());
try {
if (segmentPlaylistUrl == null) {

View File

@ -2,6 +2,7 @@ package ctbrec.recorder.server;
import ctbrec.Config;
import ctbrec.io.HttpClient;
import ctbrec.recorder.SimplifiedLocalRecorder;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.json.JSONObject;
@ -68,6 +69,14 @@ public class DebugServlet extends AbstractCtbrecServlet {
HttpClient.getGLOBAL_HTTP_CONN_POOL().connectionCount(),
HttpClient.getGLOBAL_HTTP_CONN_POOL().idleConnectionCount());
var rlock = SimplifiedLocalRecorder.STATS.statsLock.readLock();
rlock.lock();
try {
text += String.format("Time between download iterations = %s\n", SimplifiedLocalRecorder.STATS.stats.toString());
} finally {
rlock.unlock();
}
log.debug("Stats Request");
resp.setContentType("text/plain");
sendResponse(resp, SC_OK, text);