简体   繁体   English

Google Analytics Management API Java包批处理未按预期工作

[英]Google Analytics Management API Java Package Batching not working as indended

I am trying to roll out the same 10 goals to a large number of websites. 我正在尝试将相同的10个目标推广到许多网站。 I have the goals stored in toAddArray and in a loop, they will create or updated based off of the current site's number of goals. 我将目标存储在toAddArray中,并在一个循环中,它们将基于当前站点的目标数来创建或更新。 First I create the batch, then I loop through adding the goals to the batch (I omitted the Goal code because the writes are not failing) and then execute the batch. 首先,我创建了批处理,然后循环通过将目标添加到批处理中(由于写入没有失败,我省略了目标代码),然后执行了批处理。

Code I am running 我正在运行的代码

        //Create batch from Analytics Object
        BatchRequest b = analytics.batch();
        // in loop determine create or update based off current Goal list size
        FOR LOOP IS HERE
        if(y < currentSize)
            {
                //some code for inserting the goal 
                analytics.management().goals().update(ACTIVE_ACCOUNT_ID, ACTIVE_PROPERTY_ID, ACTIVE_PROFILE_ID, String.valueOf(y+1), toAddArray[y]).queue(b, setCallback("Successfully Added Goal"));
            }
            else{
                // Some code for when I update the goal 
                // Send to queue
                analytics.management().goals().insert(ACTIVE_ACCOUNT_ID, ACTIVE_PROPERTY_ID, ACTIVE_PROFILE_ID, toAddArray[y]).queue(b, setCallback("Successfully Added Goal"));
            }

           FOR LOOP ENDS
           //Execute the batch 
           b.execute();

What is Happening 怎么了

When I am running this I get the callbacks for the 10 goals, the first 5-6 come back successful and the last 4 will come back with rate limit exceeded. 当我运行此命令时,我得到了10个目标的回调,前5-6个成功返回,而后4个超出了速率限制。 To my knowledge, the whole point of the batching system is to compile the URLs into one hit and send them all at once to decrease the load on the server. 据我所知,批处理系统的全部目的是将URL编译为一个匹配,然后一次发送所有URL,以减少服务器上的负载。

This system seems to be working more like a queueing system which has its place but does not help me decrease the number of writes I am working with. 这个系统似乎更像是一个排队系统,虽然有它的位置,但是并不能帮助我减少正在处理的写入次数。 Since I am writing 10 goals to 1000 or so websites I am looking at 10k writes a day. 由于我要为1000个左右的网站编写10个目标,因此我每天要写10k。 With a limit of 500 writes per project a day that makes this a 20 day thing. 每个项目每天限制500次写入,因此这需要20天的时间。 If I only have a write per profile it would be a 2 day thing. 如果我每个配置文件只写一次,那将是2天的事情。 I have requests in with the Google team to increase my API quotas and add the Goal update beta access to 5 more projects so I can start switching keys, but in the meantime, I want to understand if there is something I can do to get batching to work as one single write. 我已与Google团队联系,要求增加我的API配额,并向另外5个项目添加“目标更新”测试版访问权限,以便我可以开始切换键,但是与此同时,我想了解是否可以做一些事情来进行批处理一次写。

Performance gains using batching are only called out for Permissions ( user management docs ). 使用批处理获得的性能提升仅针对权限( 用户管理文档 )进行。

I believe you are correct when you say that the calls are made as if you made them one at a time. 我相信您说的是正确的,就像您一次拨打一个电话一样。 You're probably getting quota errors when you send 10 call all at once. 一次发送10个电话时,您可能会遇到配额错误。 I'm guessing it's the 1.5qps per Account ID write limit 我想这是每个帐户ID写入限制1.5qps

If you need to make that many writes you may need to implement exponential backoff. 如果需要进行大量写入,则可能需要实现指数补偿。

I hope this helps, and good luck :) 我希望这个帮助能祝你好运 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM