每分钟/每小时记录 API 调用的最佳方式
我们在 Rails Web 服务中使用反向地理编码,并且在通过 geokit 使用 Google 反向地理编码器时遇到了配额问题。我们还实施了 simple-geo 服务,我希望能够跟踪我们每分钟/小时发出的请求数。
对于跟踪我们的反向地理编码调用有什么建议吗?
我们的代码如下所示。你会做其中任何一个吗?
- 每天在后台添加自定义记录器和进程
- 使用我不知道的超级神奇的 gem,它可以轻松地进行配额和评级
- 插入数据库调用并在那里进行查询。
注意:我不需要实时数据,只是想知道每小时内我们通常的请求和每小时的最大请求是多少。 (以及每月请求总数)
def use_simplegeo(lat, lng)
SimpleGeo::Client.set_credentials(SIMPLE_GEO_OAUTHTOKEN, SIMPLE_GEO_OAUTHSECRET)
# maybe do logging/tracking here?
nearby_address = SimpleGeo::Client.get_nearby_address(lat, lng)
located_location = LocatedLocation.new
located_location.city = nearby_address[:place_name]
located_location.county = nearby_address[:county_name]
located_location.state = nearby_address[:state_code]
located_location.country = nearby_address[:country]
return located_location
end
谢谢!
We are using reverse-geocoding in a rails webservice, and have run into quota problems when using the Google reverse geocoder through geokit. We are also implementing the simple-geo service, and I want to be able to track how many requests per minute/hour we are making.
Any suggestions for tracking our reverse-geocoding calls?
Our code will look something like the following. Would you do any of these?
- Add a custom logger and process in the background daily
- Use a super-fantastic gem that I don't know about that does quotas and rating easily
- Insert into database a call and do queries there.
Note: I don't need the data in real-time, just want to be able to know in an hourly period, what's our usual and max requests per hour. (and total monthly requests)
def use_simplegeo(lat, lng)
SimpleGeo::Client.set_credentials(SIMPLE_GEO_OAUTHTOKEN, SIMPLE_GEO_OAUTHSECRET)
# maybe do logging/tracking here?
nearby_address = SimpleGeo::Client.get_nearby_address(lat, lng)
located_location = LocatedLocation.new
located_location.city = nearby_address[:place_name]
located_location.county = nearby_address[:county_name]
located_location.state = nearby_address[:state_code]
located_location.country = nearby_address[:country]
return located_location
end
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里的第一部分不是回答您所问的问题,但如果之前没有考虑过的话,我会有所帮助。
您是否考虑过不使用服务器(即通过 Geokit)进行反向地理编码,而是由客户端完成?换句话说,一些 Javascript 加载到用户的浏览器中,代表您的服务进行 Google 地理编码器 API 调用。
如果您的应用程序可以支持这种方法,那么这有很多优点:
如果您仍然想记录地理编码器查询,并且担心对主应用程序数据库的性能影响,那么您可以考虑以下选项之一:
The first part here is not answering the question you are asking but my be helpful if haven't considered it before.
Have you looked at not doing your reverse geocoding using your server (i.e. through Geokit) but instead having this done by the client? In other words some Javascript loaded into the user's browser making Google geocoder API calls on behalf of your service.
If your application could support this approach than this has a number of advantages:
If you still would like to log your geocoder queries and you are concerned about the performance impact to your primary application database then you might consider one of the following options: