WordRider Home
LC
option to discard slow proxies
April 04, 2012 01:17PM
First of all I want to thank you – FreeRapid is truly a great project! smiling smiley

I often have trouble with slow proxies screwing up downloads (I have to re-get 3-4 files manually while the rest all finished hours ago).
How about an option like this:

X discard proxies if slower than ___5 kb/s after ___60 seconds, ___3 times
(one checkbox, three int-spinners)

When checked, this would remove a proxy if it was slower than 5 kb/s (on average!) after a minute for three times.
In other words: it would restart the download with a different proxy if after a minute the average transfer rate would be below 5 kb/s. If this happened three times the proxy would be deleted and never used again.

I wanted to implement this myself, but when I looked into the code I got lost, honestly.

I hope you find something like this to be a useful idea.
Keep up the good work!
LC
LC
Implemented as a dirty hack - works great thumbs up
April 10, 2012 09:17AM
I've implemented it as a quick and dirty hack. Works like a miracle!


patch:



Index: src/cz/vity/freerapid/core/tasks/SpeedRegulator.java
===================================================================
--- src/cz/vity/freerapid/core/tasks/SpeedRegulator.java	(revision 3534)
+++ src/cz/vity/freerapid/core/tasks/SpeedRegulator.java	(working copy)
@@ -2,10 +2,12 @@
 
 import cz.vity.freerapid.core.AppPrefs;
 import cz.vity.freerapid.core.UserProp;
+import cz.vity.freerapid.gui.managers.ManagerDirector;
 import cz.vity.freerapid.model.DownloadFile;
 import cz.vity.freerapid.plugins.webclient.DownloadState;
 
 import javax.swing.event.SwingPropertyChangeSupport;
+import java.awt.datatransfer.StringSelection;
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
 import java.util.*;
@@ -17,6 +19,9 @@
  * @author Vity
  */
 public final class SpeedRegulator implements PropertyChangeListener {
+// My modifications:
+    private ManagerDirector manager_director;
+
     private final static Logger logger = Logger.getLogger(SpeedRegulator.class.getName());
 
     private Map downloading = new Hashtable(10);
@@ -29,8 +34,10 @@
     private volatile long speed;
     private volatile float averageSpeed;
 
+// My modifications:
+    public SpeedRegulator( ManagerDirector d ) {
+        this.manager_director = d;
 
-    public SpeedRegulator() {
         timer = null;
         speed = 0;
         averageSpeed = 0;
@@ -180,7 +187,9 @@
             file.setTokensLimit(Integer.MAX_VALUE);
             file.setSpeed(0);
             file.setAverageSpeed(0);
-            downloading.put(file, new DownloadFileInfo(task));
+// My modifications:
+            downloading.put(file, new DownloadFileInfo( task, manager_director ));
+
             if (timer == null) {
                 timer = new Timer("SpeedRegulatorTimer");
                 timer.schedule(new TimerTask() {
@@ -226,6 +235,10 @@
     }
 
     private static class DownloadFileInfo {
+// My modifications:
+DownloadFile debug_exception;
+        private ManagerDirector manager_director;
+
         private volatile long counter = 0;
         private long lastSize = 0;
         private int noDataTimeOut = 0; //XXX seconds to timeout
@@ -243,7 +256,10 @@
         private float averageSpeed;
         private long downloadedStart;
 
-        DownloadFileInfo(DownloadTask task) {
+// My modifications:
+        DownloadFileInfo( DownloadTask task, ManagerDirector director ) {
+            this.manager_director = director;
+
             this.task = task;
             this.file = task.getDownloadFile();
             downloadedStart = this.file.getDownloaded();
@@ -275,8 +291,43 @@
 
             // task.setSpeed(speed);
             file.setSpeed(speed);
-            if (speed == 0) {
-                if (++noDataTimeOut >= NO_DATA_TIMEOUT_LIMIT) { //X seconds with no data
+// My modifications:
+            final long Default_Min_Seconds_Before_Proxy_Avg_Chk = 20 * 1000;         // * 1000 = seconds
+            final float Default_Proxy_Min_Avg_Speed_Before_50_Percent = 15 * 1024.0F;   // * 1024 = kb/s
+            final float Default_Proxy_Min_Avg_Speed_Before_80_Percent = 10 * 1024.0F;
+            final float Default_Proxy_Min_Avg_Speed_Before_90_Percent = 5 * 1024.0F;
+            final float Default_Proxy_Min_Avg_Speed_After_90_Percent = 1 * 1024.0F;
+            long current_time = System.currentTimeMillis();
+            String proxy_url = file.getConnectionSettings().getProxyURL();
+            boolean proxy_is_too_slow = false;
+            double percent_complete = ( 100.0 / file.getFileSize() ) * lastSize;
+            if( ( ( current_time - startTime ) > Default_Min_Seconds_Before_Proxy_Avg_Chk ) ) {
+                if( ( percent_complete < 50.0 ) &&
+                    ( file.getAverageSpeed() < Default_Proxy_Min_Avg_Speed_Before_50_Percent ) ) {
+//String s = debug_exception.getFileName();
+                    proxy_is_too_slow = true;
+                } else if( ( percent_complete < 80.0 ) &&
+                           ( file.getAverageSpeed() < Default_Proxy_Min_Avg_Speed_Before_80_Percent ) ) {
+//String s = debug_exception.getFileName();
+                    proxy_is_too_slow = true;
+                } else if( ( percent_complete < 90.0 ) &&
+                           ( file.getAverageSpeed() < Default_Proxy_Min_Avg_Speed_Before_90_Percent ) ) {
+//String s = debug_exception.getFileName();
+                    proxy_is_too_slow = true;
+                } else if( file.getAverageSpeed() < Default_Proxy_Min_Avg_Speed_After_90_Percent ) {
+//String s = debug_exception.getFileName();
+                    proxy_is_too_slow = true;
+                }
+                if( proxy_is_too_slow ) {
+//String s = debug_exception.getFileName();
+                    manager_director.getClientManager().setConnectionEnabled( file.getConnectionSettings(), false );
+                    manager_director.getClientManager().updateProxyConnectionList();
+                }
+            }
+            if( speed == 0 || proxy_is_too_slow ) {
+                if( proxy_is_too_slow || ( ++noDataTimeOut >= NO_DATA_TIMEOUT_LIMIT ) ) { //X seconds with no data
+                    if( proxy_is_too_slow )
+                        noDataTimeOut = 0;
                     logger.info("Cancelling download - no downloaded data during " + NO_DATA_TIMEOUT_LIMIT + " seconds");
                     averageSpeed = 0;
                     task.setConnectionTimeOut(true);
Index: src/cz/vity/freerapid/gui/managers/ClientManager.java
===================================================================
--- src/cz/vity/freerapid/gui/managers/ClientManager.java	(revision 3534)
+++ src/cz/vity/freerapid/gui/managers/ClientManager.java	(working copy)
@@ -35,7 +35,8 @@
     private final List availableConnections = new ArrayList(2);
     private Stack workingClientsPool = new Stack();
     private static final String PROXY_LIST_DEFAULT_PATH = new File(Utils.getAppPath(), "proxy.list").getAbsolutePath();
-    public static final int MAX_DOWNLOADING = 10;
+// My modifications:
+    public static final int MAX_DOWNLOADING = 100000;
 
     private ConnectionSettings defaultConnectionSettings = new ConnectionSettings();
 
Index: src/cz/vity/freerapid/gui/managers/ManagerDirector.java
===================================================================
--- src/cz/vity/freerapid/gui/managers/ManagerDirector.java	(revision 3534)
+++ src/cz/vity/freerapid/gui/managers/ManagerDirector.java	(working copy)
@@ -240,7 +240,8 @@
 
     public SpeedRegulator getSpeedRegulator() {
         if (speedRegulator == null) {
-            speedRegulator = new SpeedRegulator();
+// My modifications:
+            speedRegulator = new SpeedRegulator( this );
         }
         return speedRegulator;
     }
Re: option to discard slow proxies
October 31, 2012 06:02PM
How do I implement this patch?
Sorry, only registered users may post in this forum.

Click here to login