-Smart proxy selection (auto proxy speed benchmark)
This commit is contained in:
tonikelope 2018-10-27 16:56:00 +02:00
parent 7d01d99a94
commit 27cc6eda1f
9 changed files with 43 additions and 15 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.tonikelope</groupId>
<artifactId>MegaBasterd</artifactId>
<version>5.54</version>
<version>5.55</version>
<packaging>jar</packaging>
<dependencies>
<dependency>

View File

@ -20,7 +20,7 @@ import java.net.URL;
*/
public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
public static final double SLOW_CHUNK_PER = 0.5;
public static final double SLOW_PROXY_PERC = 0.5;
private final int _id;
private final Download _download;
private volatile boolean _exit;
@ -103,7 +103,7 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
int http_error = 0, conta_error = 0;
boolean timeout, chunk_error = false, slow_chunk = false;
boolean timeout, chunk_error = false, slow_proxy = false;
String worker_url = null, current_smart_proxy = null;
@ -126,7 +126,7 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
String chunk_url = ChunkManager.genChunkUrl(worker_url, _download.getFile_size(), chunk_offset, chunk_size);
if ((http_error == 509 || slow_chunk) && MainPanel.isUse_smart_proxy() && !MainPanel.isUse_proxy()) {
if ((http_error == 509 || slow_proxy) && MainPanel.isUse_smart_proxy() && !MainPanel.isUse_proxy()) {
if (_proxy_manager == null) {
@ -208,7 +208,7 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
timeout = false;
slow_chunk = false;
slow_proxy = false;
File tmp_chunk_file = null, chunk_file = null;
@ -322,14 +322,17 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
_download.getChunkmanager().secureNotify();
//Chunk download speed benchmark
long chunk_speed = Math.round((double) chunk_size / ((double) (finish_chunk_time - init_chunk_time - paused) / 1000));
if (current_smart_proxy != null) {
if (chunk_speed < Math.round(((double) _download.getMain_panel().getGlobal_dl_speed().getMaxAverageGlobalSpeed() / _download.getChunkworkers().size()) * SLOW_CHUNK_PER)) {
//Proxy speed benchmark
long chunk_speed = Math.round((double) chunk_size / ((double) (finish_chunk_time - init_chunk_time - paused) / 1000));
Logger.getLogger(getClass().getName()).log(Level.INFO, "{0} Worker WARNING -> CHUNK DL SPEED: {1}/s is SLOW", new Object[]{_id, formatBytes(chunk_speed)});
if (chunk_speed < Math.round(((double) _download.getMain_panel().getGlobal_dl_speed().getMaxAverageGlobalSpeed() / _download.getMain_panel().getDownload_manager().calcTotalSlotsCount()) * SLOW_PROXY_PERC)) {
slow_chunk = true;
Logger.getLogger(getClass().getName()).log(Level.INFO, "{0} Worker WARNING -> PROXY SPEED: {1}/s is SLOW", new Object[]{_id, formatBytes(chunk_speed)});
slow_proxy = true;
}
}
}
}

View File

@ -1624,4 +1624,9 @@ public final class Download implements Transference, Runnable, SecureSingleThrea
return _status_error;
}
@Override
public int getSlotsCount() {
return getChunkworkers().size();
}
}

View File

@ -22,7 +22,7 @@ public final class GlobalSpeedMeter implements Runnable {
private final ConcurrentHashMap<Transference, HashMap> _transferences;
private long _speed_counter;
private long _speed_acumulator;
private long _max_avg_speed;
private volatile long _max_avg_speed;
GlobalSpeedMeter(TransferenceManager trans_manager, JLabel sp_label, JLabel rem_label) {
_speed_label = sp_label;
@ -34,8 +34,8 @@ public final class GlobalSpeedMeter implements Runnable {
_max_avg_speed = 0L;
}
public long getAverageGlobalSpeed() {
return Math.round((double) _speed_acumulator / (_speed_counter));
private long _getAverageGlobalSpeed() {
return Math.round((double) _speed_acumulator / _speed_counter);
}
public void attachTransference(Transference transference) {
@ -173,7 +173,7 @@ public final class GlobalSpeedMeter implements Runnable {
_speed_counter++;
_speed_acumulator += sp;
long avg_speed = getAverageGlobalSpeed();
long avg_speed = _getAverageGlobalSpeed();
if (avg_speed > _max_avg_speed) {
_max_avg_speed = avg_speed;

View File

@ -47,7 +47,7 @@ import java.io.File;
*/
public final class MainPanel {
public static final String VERSION = "5.54";
public static final String VERSION = "5.55";
public static final int THROTTLE_SLICE_SIZE = 16 * 1024;
public static final int DEFAULT_BYTE_BUFFER_SIZE = 16 * 1024;
public static final int STREAMER_PORT = 1337;

View File

@ -52,4 +52,6 @@ public interface Transference {
boolean isStatusError();
int getSlotsCount();
}

View File

@ -208,6 +208,19 @@ abstract public class TransferenceManager implements Runnable, SecureSingleThrea
secureNotify();
}
public int calcTotalSlotsCount() {
int slots = 0;
for (Transference trans : _transference_running_list) {
slots += trans.getSlotsCount();
}
return slots;
}
public void closeAllPreProWaiting() {
_transference_preprocess_queue.clear();

View File

@ -1219,4 +1219,9 @@ public final class Upload implements Transference, Runnable, SecureSingleThreadN
}
}
@Override
public int getSlotsCount() {
return getChunkworkers().size();
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 176 KiB

After

Width:  |  Height:  |  Size: 181 KiB