goagent/goagent — pull request #6 by rlei (2014-04-18 06:59:49+00:00)
Title: make URLFETCH pick appid randomly and avoid retrying with the same out-of-quota appid again

Although allowing user to configure multiple appids to work around GAE's 1GB/day limit, GoAgent doesn't really distribute its proxy requests randomly with these appids. It only shuffles the appid list at startup, but will always use the first one in the shuffled list, until it runs of of quota. Then it will randomly pick an appid in the list to retry, and the out-of-quota appid still get a chance to be chosen again.

Consider you have a two appid list. When the first one runs out of quota, it will still have a 50% chance to be chosen again in the next retry.

This pull request change URLFETCH to randomly pick an appid at the beginning, and make sure it won't get picked again in the following retries.

This isn't a perfect fix but should work well enough :)

说明:

GoAgent只在启动时随机打乱appid列表一次，之后发送请求时总是固定用第一个appid，直到其流量用完（收到503 error）。之后重试时又会在所有appid里面随机抽取一个appid，这样又可能抽到已经用完quota的appid。例如，如果配置了两个appid，有50%的机会第一次重试就直接失败。

这个修改让URLFETCH随机选择appid，保证多个appid的流量能够基本上平均使用，并且在重试时确保最近503的appid不被再次选到。虽然不是最完美的fix，但应该已经够用了 :)