Phex segment rating and prioritisation

For Phex 2.1 and later

implemented by Nick Farrell (n ecks f at sf)
What are segments?
If you click on the segments tab when a downloading file is selected, you will see that each file is divided into a number of segments. Some segments are complete (ie: all the data has been downloaded), incomplete, or empty. Each candidate Phex connects to (that is, a remote computer containing some data we're interested in) can service only one segment at a time. Segments can be merged and split to try to maximise efficiency.
What do you mean by rating?
Each segment has a rating. It is used when a candidate is ready to be assigned to a segment, to help determine the order in which Phex tries to assign segments to the candidate.
Why bother?
Prior to version 2.1(beta), Phex more-or-less randomly allocated segments to candidates. The most important reasons for adding this feature are:
How does the segment rating work?
This is a little complicated, and you might want to skip on to the next questions. :-) First a candidateRating list is assembled and maintained. Every candidate who is unable to provide all of the file registers the parts of the file it has here. Phex watches the speed at which it is able to download data from this candidate and records this in the same list.
Candidate nameCandidate speedPart of file
X10000-50
X100080-100
Y20000-20
Y200090-100
Every 10 seconds or so another list is created, based on the above list. It more-or-less adds up the candidates' total speeds for each part of the file.
Part of fileTotal candidate speed
0-203000
21-501000
80-891000
90-1003000
Segments are then assigned a value taken from this list.
How does the rating affect the prioritisation of segments?
Normally, Phex will assign the lowest-rated segment to the first available candidate. Only unallocated and incomplete can be assigned, for obvious reasons. In addition, and equally obvious, a segment will not be assigned if the candidate in unable to provide that particular portion of the file. If two segments are equally rated, the one closest to the start of the file will be assigned. In the above example, that would mean a segment starting at position "21" would be the highest-priority segment. If the candidate is candidate "Y", however, it will not have this part of the file and will instead deliver a segment starting at position "0". The above method is named Prioritise by rating and is the default method, when a file is not recognised as being streamable. There are two other methods: Prioritise by position and Prioritise for preview.
What do you mean by streamable and unstreamable?
Streamable just means that the file is somehow useful to you before it's fully downloaded. For example, AVI or MP3 streams can be used before the entire file has been downloaded. Unstreamable is simply the opposite: if any of the file is missing the whole thing is pretty much useless, regardless of whether it's the start, the end, or somewhere in the middle that's missing.
What are these other 2 prioritisation methods?
Prioritise by position: ignore the rating for a segment, and always try to get the segments closest to the start of the file first. Prioritise for preview: a hybrid of the other two methods. Get the first 10% of the file first, then prioritise by rating.
How can I use them?
When a new download is started, Phex, looks at the suffix of the filename and guesses whether the file is streamable or not. If it is, it prioritises for preview. Otherwise, it prioritises by rating. You can change the current priority for a downloading file by right-clicking on the file and selecting 'ordering'. Any change will take effect at the next calculating point (ie: roughly every 10 seconds)
How can I change the default ordering method?
In your phex.cfg file you will see a variable orderingMethod, which is a 3-digit number. The first value is used if a streamable file is detected, the second if an unstreamable file is detected, and the first if neither is detected.
ordering methodvalue
Prioritise by position1
Prioritise by rating2
Prioritise for preview3
How can I change the definition of streamed and unstreamed files?
Also in phex.cfg, look for streamableSuffixes_#. Simply add, delete or modify the values as you prefer. For advanced users: the suffixes are actually regular expressions, as you may guess. If you create an entry starting with ^ and ending with $ it will match the whole file, not just the suffix.
I don't know when to stop. Please tell me more!
Well OK. Some of the following borders on trivia, but you asked for it.
I have an interesting/useful idea relating to this!
Great! Email me, or even better post it in the Phex forums on sourceforge. Some things I would particularly appreciate: