View Single Post
  #3 (permalink)  
Old August 29th, 2008
mvchante mvchante is offline
Novicius
 
Join Date: August 26th, 2008
Posts: 2
mvchante is flying high
Default

Removing the synchronized added in the diff you mentioned does indeed eliminate the GUI lag; however, I presume those synchronized's are needed?


On a broader look: When the GUI renders, it gets the most current values from BandwidthController by-way-of SWDownloadFile . This causes the EventDispatchThread to block until it can retrieve this value from the data transfer thread.


As a test, I implemented a cache (see below). This showed a measurable improvement in GUI response.



I believe the ultimate solution would be to have SWDownloadFile listen to BandwidthController to receive updated values when available /instead of/ having SWDownloadFile query BandwidthController for each request and thus blocking.


Comments?









Code:


    public static class EdtCache
    {
        private final SWDownloadFile download   ;
        private final long           updateRate ;

        private long lastUpdate             ;
//        private int  shortTermTransferRate  ;
        private int  longTermTransferRate   ;
        private long transferSpeed          ;
        private long downloadThrottlingRate ;

        public EdtCache(SWDownloadFile download, long updateRate)
        {
            this.download = download;
            this.updateRate = updateRate;
            update();
        }

        private void update()
        {
try {
//            shortTermTransferRate   = download.getShortTermTransferRate  ();
            longTermTransferRate    = download.getLongTermTransferRate   ();
            transferSpeed           = download.getTransferSpeed          ();
            downloadThrottlingRate  = download.getDownloadThrottlingRate ();
            lastUpdate              = System.currentTimeMillis();
} catch (RuntimeException re) {
    re.printStackTrace();
    throw re;
}
        }

        private boolean needsUpdate() { return System.currentTimeMillis() - lastUpdate > updateRate; }

//        public int getShortTermTransferRate()
//        {
//            if (needsUpdate()) update();
//            return shortTermTransferRate;
//        }

        public int getLongTermTransferRate()
        {
            if (needsUpdate()) update();
            return longTermTransferRate;
        }

        public long getTransferSpeed()
        {
            if (needsUpdate()) update();
            return transferSpeed;
        }

        public long getDownloadThrottlingRate()
        {
            if (needsUpdate()) update();
            return downloadThrottlingRate;
        }

    }

Cheers,
M. V`Chante

Last edited by mvchante; August 29th, 2008 at 11:24 PM. Reason: typo
Reply With Quote