Extremely slow api calls caused by {method 'next_event' of 'grpc._cython.cygrpc.SegregatedCall' objects}

194 views
Skip to first unread message

Adam Walters

unread,
May 16, 2023, 1:43:23 PM5/16/23
to Google Ads API and AdWords API Forum
Hello,

Recently my program started running extremely slow and upon further investigation found that this '{method 'next_event' of 'grpc._cython.cygrpc.SegregatedCall' objects}' was taking over 5 seconds per call.

I am using all of the latest versions grpc and google-ads packages.

Below is an example of the code that is running and the results from a cProfile run:
from google.ads.googleads.client import GoogleAdsClient
from google.ads.googleads.v13.services.services.google_ads_service import pagers
import logging

logging.basicConfig(level=logging.INFO, format='[%(asctime)s - %(levelname)s] %(message).5000s')
logging.getLogger('google.ads.googleads.client').setLevel(logging.INFO)

client = GoogleAdsClient.load_from_storage("google-ads.yaml")
google_ads_service = client.get_service("GoogleAdsService", version='v13')

class GoogleQuery:
"""A class to query Google Ads API

Attributes:
client: An initialized GoogleAdsClient instance.
mcc_id: The Google Ads MCC ID
search_accounts_query: A query to return all search accounts
display_accounts_query: A query to return all display accounts

Methods:
get_existing_search_accounts: Returns a dictionary of existing search accounts
get_existing_display_accounts: Returns a dictionary of existing display accounts
run_gaql_query: Runs a GAQL query and returns a Pager object
"""

def __init__(self):
self.client = client
self.mcc_id = "XXXXXXXXXX"
self.search_accounts_query = """SELECT
customer_client.id,
customer_client.resource_name,
customer_client.descriptive_name,
customer_client.manager,
customer_client.applied_labels
FROM
customer_client
WHERE
customer_client.manager = false
AND customer_client.id IS NOT NULL
AND customer_client.descriptive_name LIKE '%Search%'
AND customer.status = 'ENABLED'"""

@staticmethod
def run_gaql_query(query: str, customer_id) -> pagers.SearchPager:
"""runs GAQL query through Google Ads API
Args:
customer_id: customer ID being queried
query: the actual GAQL query being ran
Returns:
Returns a pagers.SearchPager response of the raw data
"""
return google_ads_service.search(
customer_id=customer_id,
query=query
)

def get_existing_search_accounts(self) -> dict:
"""runs GAQL query through Google Ads API

Returns:
Returns a dict of {internal_id, account_name}
"""
response = self.run_gaql_query(self.search_accounts_query, self.mcc_id)
return {row.customer_client.descriptive_name[-8:]: row.customer_client.descriptive_name for row in response}

gaql = GoogleQuery()
gaql.get_existing_search_accounts()

# cProfile Results from above code Tue May 16 13:31:28 2023    output_test.pstats

         991213 function calls (973122 primitive calls) in 10.099 seconds

   Ordered by: internal time
   List reduced from 6168 to 20 due to restriction <20>

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    7.398    7.398    7.401    7.401 {method 'next_event' of 'grpc._cython.cygrpc.SegregatedCall' objects}

Google Ads API Forum Advisor

unread,
May 17, 2023, 4:59:02 AM5/17/23
to ad...@digible.com, adwor...@googlegroups.com

Hi,

Thank you for reaching out to Google Ads API Support.

Can you confirm if you are using the Python client library? If yes, it seems like your concern is more on the implementation / integration of our client libraries rather than anything specific to Google Ads API itself. That said, I would recommend reaching out to the developer who maintains our client libraries Python (Github Issues) in the link below.

Additionally, you may also check and confirm if you have followed the installation guide and configuration guide of the Python client library.

Reference links included in this email:

Regards,

Google Logo Google Ads API Team


ref:_00D1U1174p._5004Q2lIX16:ref

Adam Walters

unread,
May 17, 2023, 2:42:12 PM5/17/23
to Google Ads API Forum Advisor, adwor...@googlegroups.com
Hello,

Yes, I am using the Python client library. It had been working as expected and then all of a sudden seemed to fall off. It appears that the client library is installed and configured correctly.




Adam Walters

 Marketing Operations Engineer


 AUTHENTICITY | FOCUS | CURIOSITY | HUMILITY | HAPPINESS


Phone: (317) 840-1645

Email:   ad...@digible.com



This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited.



Google Ads API Forum Advisor

unread,
May 18, 2023, 12:39:36 PM5/18/23
to ad...@digible.com, adwor...@googlegroups.com

Hi Adam,

Thanks for getting back with us.

Thank you for your confirmation, as mentioned in the previous email, as this is client library issues, we recommend you reach out to the developer who maintains our client libraries Python (Github Issues) in the link below. 

Links included in this email:


Regards,

Reply all
Reply to author
Forward
0 new messages