Skip to content

Commit 1676009

Browse files
committed
Updated throttling guidance for external API usage
1 parent e3edb08 commit 1676009

File tree

1 file changed

+65
-13
lines changed

1 file changed

+65
-13
lines changed

docs/general-development/how-to-avoid-getting-throttled-or-blocked-in-sharepoint-online.md

Lines changed: 65 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -144,25 +144,77 @@ Setting and publishing exact throttling limits sounds very straightforward, but
144144
- Reduce the frequency of calls
145145

146146

147-
- Use incremental back off to reduce the number and frequency of calls until no more throttling occurs
147+
- Decorate your traffic so we know who you are (see section on traffic decoration best practice more on that below)
148148

149-
149+
150+
If you do run into throttling, we recommend incremental back off to reduce the number and frequency of calls until no more throttling occurs.
151+
150152
Incremental back off uses progressively longer waits between retries before trying again to run the code that was throttled. You can use the GitHub code samples, later in this article, written as extension methods, to add incremental back off to your code.
151-
152-
153153

154154
Backing off is the fastest way to handle being throttled because SharePoint Online continues to log resource usage while a user is being throttled. In other words, aggressive retries work against you because even though the calls fail, they still accrue against your usage limits. The faster you back off, the faster you'll stop exceeding usage limits.
155-
156-
157-
155+
158156
For information about ways to monitor your SharePoint Online activity, see [Diagnosing performance issues with SharePoint Online](https://support.office.com/en-us/article/3c364f9e-b9f6-4da4-a792-c8e8c8cd2e86).
159-
160-
161-
157+
162158
For a broader discussion of throttling on the Microsoft Cloud, see [Throttling Pattern](http://msdn.microsoft.com/library/4baf5af2-32fc-47ab-8569-3e5c59a5ebd5.aspx).
163-
164-
165-
159+
160+
## How to decorate your http traffic to avoid throttling?
161+
162+
To ensure and maintain high-availability, some traffic may be throttled. Throttling happens when system health is at stake and one of the criteria used for throttling is traffic decoration, which impacts directly on the prioritization of the traffic. Well decorated traffic will be prioritized over traffic which is not properly decorated.
163+
164+
What is definition of undecorated traffic?
165+
166+
- Traffic is undecorated if there is no AppID/AppTitle or User Agent string in CSOM or REST API call to SharePoint Online.
167+
168+
What are the recommendation?
169+
170+
- If you have created an application, recommendation is to register and use AppID and AppTitle – This will ensure the best overall experience and best path for any future issue resolution. Include also the User Agent string information as defined in following step.
171+
172+
- Make sure to include User Agent string in your API call to SharePoint with following naming convention
173+
174+
| Type | User Agent | Description |
175+
|---|---|---|
176+
| ISV Application | ISV:CompanyName:AppName:Version | Identify as ISV and include Company Name, App Name and Version name – separated by colon |
177+
| Enterprise application | NONISV:CompanyName:AppName:Version | Identify as NONISV and include Company Name, App Name and Version name – separated by colon |
178+
179+
- If you are building your own JavaScript libraries, which are used to call SharePoint Online APIs, make sure that you include the User Agent information to your http request and potentially register your web application also as an Application, where suitable.
180+
181+
### Example of decorating traffic with User agent when using Client Side Object Model (CSOM)
182+
183+
```cs
184+
// Get access to source site
185+
using (var ctx = new ClientContext("https://contoso.sharepoint.com/sites/team"))
186+
{
187+
//Provide account and pwd for connecting to SharePoint Online
188+
var passWord = new SecureString();
189+
foreach (char c in pwd.ToCharArray()) passWord.AppendChar(c);
190+
ctx.Credentials = new SharePointOnlineCredentials("[email protected]", passWord);
191+
192+
// Add our User Agent information
193+
ctx.ExecutingWebRequest += delegate (object sender, WebRequestEventArgs e)
194+
{
195+
e.WebRequestExecutor.WebRequest.UserAgent = "NONISV:Contoso:GovernanceCheck:1.0";
196+
};
197+
198+
// Normal CSOM Call with custom User-Agent information
199+
Web site = ctx.Web;
200+
ctx.Load(site);
201+
ctx.ExecuteQuery();
202+
}
203+
```
204+
205+
### Example of decorating traffic with User agent when using REST APIs
206+
207+
Following sample is in c# format, but the similar User Agent information is recommended to be used even for the JavaScript libraries used in the SharePoint Online pages.
208+
209+
```cs
210+
HttpWebRequest endpointRequest = (HttpWebRequest)HttpWebRequest.Create(sharepointUrl.ToString() + "/_api/web/lists");
211+
endpointRequest.Method = "GET";
212+
endpointRequest.UserAgent = "NONISV:Contoso:GovernanceCheck:1.0";
213+
endpointRequest.Accept = "application/json;odata=verbose";
214+
endpointRequest.Headers.Add("Authorization", "Bearer " + accessToken);
215+
HttpWebResponse endpointResponse = (HttpWebResponse)endpointRequest.GetResponse();
216+
```
217+
166218

167219
## GitHub CSOM code samples: SharePoint Online Throttling
168220
<a name="BKMK_GitHubCSOMandRESTcodesamplesSharePointOnlineThrottling"> </a>

0 commit comments

Comments
 (0)