Bug 131109

Summary: upload/download speed calculated incorrectly
Product: [Applications] ktorrent Reporter: Michal Suchanek <hramrach>
Component: generalAssignee: Joris Guisson <joris.guisson>
Status: RESOLVED WORKSFORME    
Severity: normal    
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: unspecified   
OS: Other   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Michal Suchanek 2006-07-20 13:28:58 UTC
Version:           2.0beta1 (using KDE 3.5.3, Fink/Mac OS X)
Compiler:          Target: i686-apple-darwin8
OS:                Darwin (i386) release 8.7.1

The displayed up/down speed is comlete nonsense.

While the average speed displays something reasonable like 18.8 kB, the up/down speeds for torrents and in the status bar show horrendous numbers like 67,233.1 kB. I never noticed these speeds would go down, they just grow quickly from the moment ktorrent is started.
Comment 1 Joris Guisson 2006-07-20 21:55:18 UTC
Wow, we haven't seen that before, can you try 2.0rc1 and see if it still happens with that release ?
Comment 2 Martijn van Vliet 2006-07-23 06:47:37 UTC
Sort of a confirmation on the latest svn 565093, i did:

Remove 39% completed torrent, leave downloaded data untouched->> download torrent again and point to the old folder--> checking chunks...->> viewable: 4500+ KB/s (connection limit is 1200K, downloading with 60K on this torrent) and counting down.
Comment 3 Michal Suchanek 2006-07-24 13:04:13 UTC
yes, the torrents are probably imported.

I cannot build rc1 here.
Comment 4 Joris Guisson 2006-07-24 19:50:37 UTC
SVN commit 565881 by guisson:

Made sure in case of import, the number of imported bytes gets saved properly, so that average speeds are OK.

BUG:131109



 M  +3 -0      torrentcontrol.cpp  


--- trunk/extragear/network/ktorrent/libktorrent/torrent/torrentcontrol.cpp #565880:565881
@@ -1152,7 +1152,10 @@
 			// update chunk manager
 			cman->dataChecked(dc->getDownloaded());
 			if (auto_import)
+			{
 				down->recalcDownloaded();
+				stats.imported_bytes = down->bytesDownloaded();
+			}
 		}
 		delete dc;
 		// update the status
Comment 5 Michal Suchanek 2006-07-25 15:28:13 UTC
This does not fix the problem for me.

I tried importing a torrent and started seeding. In a few minutes the current speed displayed in ktorrent went to 800 KB/s, while the peak speed in network monitor was something between 50-160 KB/s.

The average speed displayed in ktorrent was between 5.0-5.3 KB/s, and the current speed kept growing.

Closing ktorrent had negligible impact on the speed displayed in the network monitor.
Comment 6 Joris Guisson 2006-07-25 19:03:37 UTC
I see no abnormal speed increases after an import (which should have nothing to do with the speed calculation).

Does this only happen with imports ?
Comment 7 Michal Suchanek 2006-07-26 11:43:47 UTC
no, I tried to get a new torrent, started downloading, and the same thing happens for download.

Only the numbers do not get astronomic so fast because downloading is slower.

The net monitor reports about 10 KB/s peak, and the ktorrent average is 8KB/s.

ktorrent current is 170KB/s and growing.
Comment 8 Michal Suchanek 2006-07-26 11:44:47 UTC
I am using 2.0rc1 with the patch here and the patch to fix build.
Comment 9 Joris Guisson 2006-07-26 18:22:18 UTC
Hmm, maybe there is some timing related function which behaves differently on OS X.
Comment 10 Joris Guisson 2006-07-27 18:04:30 UTC
SVN commit 566936 by guisson:

Fixed bug in speed calculation.

BUG: 131109



 M  +2 -2      apps/ktorrent/ktorrent.cpp  
 M  +1 -1      libktorrent/net/speed.cpp  
 M  +8 -8      plugins/scheduler/bwscheduler.cpp  


--- trunk/extragear/network/ktorrent/apps/ktorrent/ktorrent.cpp #566935:566936
@@ -280,8 +280,8 @@
 	PeerManager::setMaxTotalConnections(Settings::maxTotalConnections());
 //	UploadCap::instance().setMaxSpeed(Settings::maxUploadRate() * 1024);
 //	DownloadCap::instance().setMaxSpeed(Settings::maxDownloadRate()*1024);
-	net::SocketMonitor::setDownloadCap(Settings::maxDownloadRate()*1000);
-	net::SocketMonitor::setUploadCap(Settings::maxUploadRate()*1000);
+	net::SocketMonitor::setDownloadCap(Settings::maxDownloadRate()*1024);
+	net::SocketMonitor::setUploadCap(Settings::maxUploadRate()*1024);
 	m_core->setKeepSeeding(Settings::keepSeeding());
 
 	if (Settings::showSystemTrayIcon())
--- trunk/extragear/network/ktorrent/libktorrent/net/speed.cpp #566935:566936
@@ -72,7 +72,7 @@
 		else
 		{
 			//	Out() << "bytes = " << bytes << " d = " << d << endl;
-			rate = (float) bytes / (d * (1.0/1024.0));
+			rate = (float) bytes / (float)(d * 0.001);
 		}
 	}
 
--- trunk/extragear/network/ktorrent/plugins/scheduler/bwscheduler.cpp #566935:566936
@@ -177,8 +177,8 @@
 				if(!m_core)
 					break;
 				m_core->setPausedState(false);
-				net::SocketMonitor::setDownloadCap(1000 * m_core->getMaxDownloadSpeed());
-				net::SocketMonitor::setUploadCap(1000 * m_core->getMaxUploadSpeed());
+				net::SocketMonitor::setDownloadCap(1024 * m_core->getMaxDownloadSpeed());
+				net::SocketMonitor::setUploadCap(1024 * m_core->getMaxUploadSpeed());
 				break;
 			case CAT_FIRST:
 				Out(SYS_SCD|LOG_NOTICE) << prefix << "Switching to FIRST category" << endl;
@@ -187,8 +187,8 @@
 				if(!m_core)
 					break;
 				m_core->setPausedState(false);
-				net::SocketMonitor::setDownloadCap(1000 * m_schedule.getDownload(0));
-				net::SocketMonitor::setUploadCap(1000 * m_schedule.getUpload(0));
+				net::SocketMonitor::setDownloadCap(1024 * m_schedule.getDownload(0));
+				net::SocketMonitor::setUploadCap(1024 * m_schedule.getUpload(0));
 				break;
 			case CAT_SECOND:
 				Out(SYS_SCD|LOG_NOTICE) << prefix << "Switching to SECOND category" << endl;
@@ -197,8 +197,8 @@
 				if(!m_core)
 					break;
 				m_core->setPausedState(false);
-				net::SocketMonitor::setDownloadCap(1000 * m_schedule.getDownload(1));
-				net::SocketMonitor::setUploadCap(1000 * m_schedule.getUpload(1));
+				net::SocketMonitor::setDownloadCap(1024 * m_schedule.getDownload(1));
+				net::SocketMonitor::setUploadCap(1024 * m_schedule.getUpload(1));
 				break;
 			case CAT_THIRD:
 				Out(SYS_SCD|LOG_NOTICE) << prefix << "Switching to THIRD category" << endl;
@@ -207,8 +207,8 @@
 				if(!m_core)
 					break;
 				m_core->setPausedState(false);
-				net::SocketMonitor::setDownloadCap(1000 * m_schedule.getDownload(2));
-				net::SocketMonitor::setUploadCap(1000 * m_schedule.getUpload(2));
+				net::SocketMonitor::setDownloadCap(1024 * m_schedule.getDownload(2));
+				net::SocketMonitor::setUploadCap(1024 * m_schedule.getUpload(2));
 				break;
 			case CAT_OFF:
 				Out(SYS_SCD|LOG_NOTICE) << prefix << "Switching to OFF" << endl;
Comment 11 Michal Suchanek 2006-07-28 13:00:44 UTC
hmm, it wasn't actually the rc1 package. The package manager does no longer automatically install packages it builds for some reason.

rc1 and current svn do not work for me at all, they do not genereate any network traffic at all. 
Comment 12 Joris Guisson 2006-07-28 18:08:19 UTC
Huh ?

Get rid of all installed stuff of KT and do a fresh install, so that we can be sure that you are not loading the wrong libraries or plugins.
Comment 13 Michal Suchanek 2006-10-20 15:00:06 UTC
with 2.0 and later this appears to work for me as well.
Comment 14 Nicola Ruggero 2007-02-05 04:22:02 UTC
I compiled KTorrent 2.1dev04-02-07 and this bug is still present.
Torrent speed shown in the gui grows step by step to the infinite.

Sometimes KTorrent shows the same speed for each node in peers view, and of course this speed is exactly the same is shown in the torrents general view.

Sometimes KTorrent shows speed "0" in each node in peers view except one, and of course this speed is exactly the same is shown in the torrents view. But this should be correct.

Sometimes KTorrent shows the same speed for each node in peers view that have the same torrent client.

Average speeds are correct.
Comment 15 Joris Guisson 2007-03-24 13:32:20 UTC
We have been unable to reproduce this.
Comment 16 Magnus Ahlberg 2007-10-13 17:56:52 UTC
I just noticed this error on my setup after reinstalling Linux. I think I'm using the exact same version of Ktorrent as before (2.2.2), but now the download/upload speed quickly increases just as the original poster of this bug. I have been unable to reproduce this on any other computer. I've tried recompiling several times but the error remains.

If i can send any more info that would be helpful to debug this please let me know.