goagent/goagent — pull request #7 by rlei (2014-04-18 11:19:10+00:00)
Title: make URLFETCH choose appid in a round robin way to avoid retrying with the same over quota appid

Although allowing user to configure multiple appids to work around GAE's 1GB/day limit, GoAgent doesn't really distribute its proxy requests randomly through 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 over 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 pick next available appid in a round robin way.

说明:

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

这个修改让URLFETCH在当前appid over quota时，顺序使用列表中的下一个appid。