Fantastic Side-Effect of Auto-Flipping Feeds
Today I was running my Greek Engine, and with the fixes I'd made yesterday for the auto-flipping, I was totally surprised to see the feeds oscillating! Today, we have both A and B sides, so for the first time since the auto-flipping code worked, there was a situation where it shouldn't flip, but it was. It took me about a half second to realize what was happening, and to start laughing. I was being too efficient on the flipping, and when I'd drain a side, I'd quickly see that the other side had something to process, and I'd flip right over.
Then the other side would get ahead, because the non-preferred side is doing less work, and we'd drain the preferred side and flip again. It was an oscillation that was just no good. So I started tuning the code. The initial flipping thresholds were just too easy to hit. So I started by increasing the time a side must be empty. I did several tests, and finally settled on a decent value that has the side clear for about 15 seconds. If a side hasn't received a message in 15 sec, and there's other messages to process, then flip. That seemed reasonable.
I also realized that comparing the combined datagram queue and pending decoded message queues of the non-preferred side to the decoded messages of the preferred wasn't really fair. So in order to do an apples-to-apples comparison, I changed the size comparison to be the size of the pending decoded messages and I think that's going to help a little, but not much.
In the end, I had something that no longer oscillated - but it did do something quite unexpected: It "found" the faster side! It took me a minute to realize what I was seeing, but then it was obvious: if one side can really deliver messages faster than the other, and we're getting consistently empty on the preferred side, but messages on the non-preferred, then we'd be a lot better off flipping, and using the faster side.
Now this speed can come from a lot of things, but most likely it's just the electrical path, or the bandwidth of routes and switches in the path, but one thing is certain, there are very few times that the two sides are identically equal. What this change has done is to make sure that when there's a significant difference, we'll find it, and use it.
It's stuff like this that makes me glad I'm doing this kind of work. Finding unexpected benefits of a code change is really great. Too often it's the other way, but today I came out a winner. Excellent!