Organizing the downloads more efficient

Post comments about Shareaza code and discuss with other developers.
Forum rules
Home | Wiki | Rules

Organizing the downloads more efficient

Postby old_death » 07 Feb 2010 23:44

Currently, we're querying each item again and again, from the first one to the last one, and again from the first one to the last one. This way of checking each entry again and again could be made much more efficient. As I got an idea how to realize this, I decided to write this post to describe my idea for a more efficient algorithm.

It would probably be much more efficient to query only those list entries that really need attention. That's why I would like to propose a new algorithm that scales much better (or at least I think it does) than the current system.
There are two ways of implementing my Idea. A lazy and easy one and a more complicated, probably more efficient and more difficult to implement one.
The easy one is to maintain two (sorted) lists. The first of these lists will contain entries representing all active downloads , while the second one will contain all queued or currently inactive downloads.
Let's start with the second list. It contains - as already said - all currently queued downloads, sorted according to their position in the download list. Once the length of the first list drops below the amount of active downloads (according to the settings), the first entry of this list is moved to the first one.
The first list contains one entry for each active download. Each entry is composed of the download and of a time stamp (date and time) representing the next time this download requires attention. In case this list is always maintained in a way that it is kept in sorted order, we only need to check the first entry against the current time and once both match, the first download is checked/updated etc. After having checked it, it will get a new time/date time stamp and be resorted into the list.

This makes it possible to only query/update those downloads that currently need attention.

The second way of doing it is almost identical, but the lists contain not the downloads themselves, but the actions to do with these downloads. This increases the amount of work to implement and to maintain the list, but it diminishes the work needed to be done once an element advances to the first place of the list (and the time matches the current time).
User avatar
old_death
 
Posts: 1950
Joined: 13 Jun 2009 16:19

Re: Organizing the downloads more efficient

Postby ailurophobe » 09 Feb 2010 22:32

Uploads and security have the same problem. How about a single sorted list of all timed actions so you only need one timer that only checks the head of that list to see what expires or times out or "needs attention". That would remove useless iterations thru potentially long lists.
ailurophobe
 
Posts: 709
Joined: 11 Nov 2009 05:25


Return to Development Discussion

Who is online

Users browsing this forum: No registered users and 1 guest