I have made some improvements in Peer Selection Algorithm by using FULL RTT. It's real better than original one(more accurate estimate), I think. These functions has been tested for two weeks, and Squid 2.4 works fine with new peer selection algorithm.
As figure shows, we should choose a Parent Cache Peer with least Full RTT.
Furthermore, if n->rtt (Direct Acces RTT) smaller than the closest parent peer's FULL rtt and direct access is allowed, we should choose direct access rather than parent peer.
____________ n->rtt ____________ |Local Cache|<--------------------->|Destination| ------------ ------------- ^ p->stats.rtt ______________ h->rtt ^ |------------->Parent Cache| <-------------| --------------
I've added a new directive named 'minimum_direct_rtt_diff'. Thus I can use Config.minDirectRttDiff for better peer selection.
I've encountered problem about Network Database when the source server is not reachable. For instance, a record in NetDB like this
194.135.30.0 1/ 1 2023.0 26.0 immigration.kulichki.net www.kulichki.comNow we access www.kulichki.com if this network is unreachable for some reasons. A new record is like this
194.135.30.0 1/ 2 2023.0 26.0 immigration.kulichki.netThe RTT is still 2023, and 'recv' = 1 / 'Sent' = 2 ' means the ICMP packet miss. Thus, peer selection algorithm still consider '194.135.30.0' is reachable and make a mistake. Now I have to stop Squid and delete 'netdb_state' in cache directory, then start Squid again to make new fresh NetDB.
I think Squid should set the RTT to zero when ICMP packet miss. NetDB should represent the latest network condition for peer selection. The More accurater data NetDB keeps, the better peer selection algorithm works.
Another problem is that NetDB records cannot saved current data of NetDB to file 'netdb_state' before shutting down itself. The current data of NetDB may be useful when startup next time.
BTW, There is no variable named 'hops' in struct _peer.stats . How to add it and make it worked? I wanna use peer.stats.hops to calculate FULL HOPS. In function 'netdbClosestParent',
FULL_HOPS= peer.stats.hops + h->hops
FULL_HOPS can help netdbClosestParent choose Peer with least FULL RTT and least FULL HOPS.