tune batch page size for better performance over tor

This commit is contained in:
Craig Raw 2022-01-31 12:11:27 +02:00
parent 20a99e3236
commit 3820b9838d
4 changed files with 24 additions and 6 deletions

View file

@ -60,7 +60,7 @@ public class Config {
private boolean useProxy;
private String proxyServer;
private int maxServerTimeout = DEFAULT_MAX_TIMEOUT;
private int batchPageSize = DEFAULT_PAGE_SIZE;
private int maxPageSize = DEFAULT_PAGE_SIZE;
private boolean usePayNym;
private boolean sameAppMixing;
private Double appWidth;
@ -503,8 +503,8 @@ public class Config {
return maxServerTimeout;
}
public int getBatchPageSize() {
return batchPageSize;
public int getMaxPageSize() {
return maxPageSize;
}
public boolean isUsePayNym() {

View file

@ -17,7 +17,7 @@ import static com.sparrowwallet.sparrow.net.BatchedElectrumServerRpc.DEFAULT_MAX
import static com.sparrowwallet.sparrow.net.BatchedElectrumServerRpc.RETRY_DELAY_SECS;
public class PagedBatchRequestBuilder<K, V> extends AbstractBuilder {
public static final int DEFAULT_PAGE_SIZE = 500;
public static final int DEFAULT_PAGE_SIZE = 100;
private final AtomicLong counter;
@ -147,11 +147,19 @@ public class PagedBatchRequestBuilder<K, V> extends AbstractBuilder {
}
private int getPageSize() {
int pageSize = Config.get().getBatchPageSize();
int pageSize = Config.get().getMaxPageSize();
if(pageSize < 1) {
pageSize = DEFAULT_PAGE_SIZE;
}
//Halve the page size if there have been timeouts
if(transport instanceof TimeoutCounter timeoutCounter) {
int timeouts = timeoutCounter.getTimeoutCount();
if(timeouts > 0) {
return pageSize / 2;
}
}
return pageSize;
}

View file

@ -22,7 +22,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
public class TcpTransport implements Transport, Closeable {
public class TcpTransport implements Transport, Closeable, TimeoutCounter {
private static final Logger log = LoggerFactory.getLogger(TcpTransport.class);
public static final int DEFAULT_PORT = 50001;
@ -251,6 +251,11 @@ public class TcpTransport implements Transport, Closeable {
}
}
@Override
public int getTimeoutCount() {
return readTimeoutIndex;
}
private static class Rpc {
public String id;

View file

@ -0,0 +1,5 @@
package com.sparrowwallet.sparrow.net;
public interface TimeoutCounter {
int getTimeoutCount();
}