Antipattern: configurare una quota non distribuita
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Stai visualizzando la documentazione di Apigee e Apigee hybrid.
Visualizza la documentazione di
Apigee Edge.
Apigee offre la possibilità di configurare il numero di richieste a un proxy API consentite per un periodo di tempo specifico utilizzando i criteri per le quote.
Antipattern
Una richiesta al proxy API può essere fornita da uno o più componenti Apigee distribuiti, chiamati processori di messaggi. Se esistono più processori di messaggi configurati per la fornitura delle richieste API, è probabile che la quota venga superata perché ogni processore di messaggi mantiene un "conteggio" separato delle richieste elaborate.
Spieghiamone il funzionamento con l'aiuto di un esempio. Prendiamo in considerazione il criterio per le quote per un proxy API:
La configurazione precedente dovrebbe consentire un totale di 100 richieste all'ora.
In pratica, tuttavia, se più processori di messaggi forniscono le richieste API, si verifica quanto segue:
Nell'illustrazione in alto:
Il criterio per le quote è configurato in modo da consentire 100 richieste all'ora.
Le richieste al proxy API vengono fornite da due processori di messaggi.
Ciascun processore di messaggi mantiene la propria variabile per il conteggio delle quote, quota_count_mp1 e quota_count_mp2, per tenere traccia del numero di richieste elaborate.
Pertanto, ciascun processore di messaggi consentirà separatamente 100 richieste API. L'effetto netto è che viene elaborato un totale di 200 richieste invece di 100 richieste.
Impatto
Questa situazione contrasta la finalità della configurazione della quota e può avere effetti negativi sui server di backend che forniscono le richieste.
I server di backend possono:
Essere stressati a causa di un traffico in entrata più elevato del previsto
Non rispondere più alle richieste API più recenti che causano errori 503
Best practice
Valuta la possibilità di impostare l'elemento <Distributed> su true nel criterio per le quote per assicurarti che venga utilizzato un contatore comune per tenere traccia delle richieste API in tutti i processori di messaggi.
L'elemento <Distributed> può essere impostato come mostrato nello snippet di codice seguente:
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-03 UTC."],[[["\u003cp\u003eThis document covers Apigee and Apigee hybrid documentation, specifically focusing on the Quota policy for managing API request limits.\u003c/p\u003e\n"],["\u003cp\u003eWhen multiple Message Processors serve API requests, each maintains an independent quota count, which can lead to exceeding the intended total request limit.\u003c/p\u003e\n"],["\u003cp\u003eThe impact of independent quota counts across message processors includes potential stress on backend servers and possible 503 errors due to excessive traffic.\u003c/p\u003e\n"],["\u003cp\u003eSetting the \u003ccode\u003e<Distributed>\u003c/code\u003e element to \u003ccode\u003etrue\u003c/code\u003e within the Quota policy ensures a unified counter across all Message Processors, aligning the actual request limit with the configured quota.\u003c/p\u003e\n"]]],[],null,["# Antipattern: Configure non-distributed quota\n\n*You're viewing **Apigee** and **Apigee hybrid** documentation.\nView [Apigee Edge](https://docs.apigee.com/api-platform/antipatterns/non-distributed-quota) documentation.*\n\nApigee provides the ability to configure the number of allowed requests to an API Proxy for\na specific period of time using the [Quota policy](/apigee/docs/api-platform/reference/policies/quota-policy).\n\nAntipattern\n-----------\n\nAn API proxy request can be served by one or more distributed Apigee components called\n*Message Processors*. If there are multiple Message Processors configured for serving API\nrequests, then the quota will likely be exceeded because each Message Processor keeps it's own\n\"count\" of the requests it processes.\n\nLet's explain this with the help of an example. Consider the following [Quota policy](/apigee/docs/api-platform/reference/policies/quota-policy) for an API\nproxy: \n\n```world-of-warcraft-toc\n\u003c!-- /antipatterns/examples/1-6.xml --\u003e\n\u003cQuota name=\"CheckTrafficQuota\"\u003e\n \u003cInterval\u003e1\u003c/Interval\u003e\n \u003cTimeUnit\u003ehour\u003c/TimeUnit\u003e\n \u003cAllow count=\"100\"/\u003e\n\u003c/Quota\u003e\n```\n\nThe above configuration should allow a total of 100 requests per hour.\n\nIn practice, however, when multiple message processors are serving the API requests, the\nfollowing happens:\n\nIn the above illustration:\n\n- The quota policy is configured to allow 100 requests per hour.\n- The requests to the API Proxy are being served by two Message Processors.\n- Each Message Processor maintains its own quota count variable, `quota_count_mp1` and `quota_count_mp2`, to track the number of requests they are processing.\n- Therefore each of the Message Processor will allow 100 API requests separately. The net effect is that a total of 200 requests are processed instead of 100 requests.\n\nImpact\n------\n\nThis situation defeats the purpose of the quota configuration and can have detrimental effects on\nthe backend servers that are serving the requests.\n\nThe backend servers can:\n\n- Be stressed due to higher than expected incoming traffic\n- Become unresponsive to newer API requests leading to 503 errors\n\nBest Practice\n-------------\n\nConsider, setting the `\u003cDistributed\u003e` element to `true` in the [Quota policy](/apigee/docs/api-platform/reference/policies/quota-policy) to\nensure that a common counter is used to track the API requests across all Message Processors.\nThe `\u003cDistributed\u003e` element can be set as shown in the code snippet below: \n\n```world-of-warcraft-toc\n\u003c!-- /antipatterns/examples/1-7.xml --\u003e\n\u003cQuota name=\"CheckTrafficQuota\"\u003e\n \u003cInterval\u003e1\u003c/Interval\u003e\n \u003cTimeUnit\u003ehour\u003c/TimeUnit\u003e\n \u003cDistributed\u003etrue\u003c/Distributed\u003e\n \u003cAllow count=\"100\"/\u003e\n\u003c/Quota\u003e\n```"]]