fixed hung socket
added missing part to protocol.txt
This commit is contained in:
committed by
Sheepit Renderfarm
parent
d137dc924b
commit
ea9d7ef425
@@ -56,6 +56,14 @@ The maximum duration between two heartbeats in seconds is given by the attribute
|
|||||||
</speedtest>
|
</speedtest>
|
||||||
</config>
|
</config>
|
||||||
|
|
||||||
|
The client then performs a speedtest on these mirror urls and POSTs back the 3 fastest ones using the "speedtest-answer" endpoint, together with the transfer time for the payload:
|
||||||
|
<speedtest>
|
||||||
|
<result target="https://static-roubaix-fr.sheepit-renderfarm.com/scene/speedtest.zip" speed="724155" ping="26"/>
|
||||||
|
<result target="https://static-nuremberg-de.sheepit-renderfarm.com/scene/speedtest.zip" speed="674325" ping="33"/>
|
||||||
|
<result target="https://static-frankfurt3-de.sheepit-renderfarm.com/scene/speedtest.zip" speed="566186" ping="26"/>
|
||||||
|
</speedtest>
|
||||||
|
|
||||||
|
|
||||||
=== Session end ===
|
=== Session end ===
|
||||||
|
|
||||||
Url: use the request type "logout" from the configuration answer.
|
Url: use the request type "logout" from the configuration answer.
|
||||||
|
|||||||
@@ -4,8 +4,11 @@ import com.sheepit.client.datamodel.SpeedTestTarget;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.net.SocketAddress;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -24,23 +27,24 @@ public class Speedtest {
|
|||||||
public Speedtest(Log log) {
|
public Speedtest(Log log) {
|
||||||
this.log = log;
|
this.log = log;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param urls the urls to the speedtest payloads
|
* @param urls the urls to the speedtest payloads
|
||||||
* @param numberOfResults number of best mirrors to return
|
* @param numberOfResults number of best mirrors to return
|
||||||
*
|
*
|
||||||
* @return An array of the mirrors with the best connection time. The size of the array is determined by <code>numberOfResults</code> or <code>urls.size()</code>
|
* @return An array of the mirrors with the best connection time. The size of the array is determined by <code>numberOfResults</code> or <code>urls.size()</code>
|
||||||
* if <code>numberOfResults > urls.size()</code>
|
* if <code>numberOfResults > urls.size()</code>
|
||||||
*/
|
*/
|
||||||
public List<SpeedTestTarget> doSpeedtests(List<String> urls, int numberOfResults) {
|
public List<SpeedTestTarget> doSpeedtests(List<String> urls, int numberOfResults) {
|
||||||
|
|
||||||
List<SpeedTestTarget> pingResult = (urls
|
List<SpeedTestTarget> pingResult = (urls
|
||||||
.stream()
|
.stream()
|
||||||
.map(this::measure)
|
.map(this::measure)
|
||||||
.sorted(ORDERED)
|
.filter(target -> target.getPing().getAverage() > 0)
|
||||||
.collect(Collectors.toList())
|
.sorted(ORDERED)
|
||||||
|
.collect(Collectors.toList())
|
||||||
);
|
);
|
||||||
|
|
||||||
numberOfResults = Math.min(numberOfResults, urls.size());
|
numberOfResults = Math.min(numberOfResults, urls.size());
|
||||||
|
|
||||||
List<SpeedTestTarget> result = new ArrayList<>(numberOfResults);
|
List<SpeedTestTarget> result = new ArrayList<>(numberOfResults);
|
||||||
@@ -66,22 +70,25 @@ public class Speedtest {
|
|||||||
result.sort(Comparator.comparing(SpeedTestTarget::getSpeedtest).reversed());
|
result.sort(Comparator.comparing(SpeedTestTarget::getSpeedtest).reversed());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private SpeedTestTarget measure(String mirror) {
|
private SpeedTestTarget measure(String mirror) {
|
||||||
long pingCount = 12;
|
long pingCount = 12;
|
||||||
var pingStatistics = LongStream
|
|
||||||
.range(0, pingCount)
|
LongStream.Builder streamBuilder = LongStream.builder();
|
||||||
.map(i -> {
|
|
||||||
try {
|
for (int i = 0; i < pingCount; i++) {
|
||||||
return runTimed(() -> ping(mirror, PORT)).first;
|
try {
|
||||||
}
|
streamBuilder.add(runTimed(() -> ping(mirror, PORT)).first);
|
||||||
catch (Exception e) {
|
}
|
||||||
this.log.error("Speedtest::ping Exception " + e);
|
catch (Exception e) {
|
||||||
return Long.MAX_VALUE;
|
this.log.error("Speedtest::ping Exception " + e);
|
||||||
}
|
pingCount /= 2;
|
||||||
})
|
streamBuilder.add(Long.MAX_VALUE);
|
||||||
.summaryStatistics();
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var pingStatistics = streamBuilder.build().summaryStatistics();
|
||||||
|
|
||||||
return new SpeedTestTarget(mirror, -1, pingStatistics);
|
return new SpeedTestTarget(mirror, -1, pingStatistics);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,13 +123,16 @@ public class Speedtest {
|
|||||||
throw new RuntimeException("Unable to execute speedtest to: " + url, e);
|
throw new RuntimeException("Unable to execute speedtest to: " + url, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int ping(String url, int port) {
|
private static int ping(String url, int port) {
|
||||||
try (Socket socket = new Socket(new URL(url).getHost(), port)) {
|
try (Socket socket = new Socket()) {
|
||||||
|
InetAddress mirrorIP = InetAddress.getByName(new URL(url).getHost());
|
||||||
|
SocketAddress socketAddress = new InetSocketAddress(mirrorIP, port);
|
||||||
|
int maxWaitingTime_ms = 3000;
|
||||||
|
socket.connect(socketAddress, maxWaitingTime_ms);
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
throw new RuntimeException("Unable to open a socket to " + url + ":" + port, e);
|
throw new RuntimeException("Unable to connect to " + url + ":" + port, e);
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user