I am inserting/upserting a document with the following structure into DocumentDB:
The request charge for upserting a document of this format is 10.67 RUs when using the default index. This seems higher than I would expect so I am looking to optimize.
After reading the performance tips in this article:
https://azure.microsoft.com/en-us/blog/performance-tips-for-azure-documentdb-part-2/
I changed the Collection Indexing Policy's Indexing Mode to Lazy. I expected the request charge to be significantly less, but it only dropped to 9.9 RUs.
I then modified the Indexing Policy again to add a bunch of properties to the Excluded Paths. Here is the custom Indexing Policy:
Adding the Excluded Paths had no effect on the RUs for an upsert - it remained at 9.9.
Am I doing something wrong? And is it possible to make upserts for this document structure consume fewer RUs?
Edit:
Here is a helper class I use for setting up and caching the connection to DocumentDB:
public class Documents
{
public static Documents Instance = new Documents();
public IReliableReadWriteDocumentClient Client { get; private set; }
private Documents()
{
var endpointUrl = ConfigurationManager.AppSettings["Microsoft.Azure.DocumentDb.EndpointUrl"];
var authKey = ConfigurationManager.AppSettings["Microsoft.Azure.DocumentDb.AuthorizationKey"];
var min = TimeSpan.FromMilliseconds(1000);
var max = TimeSpan.FromMilliseconds(5000);
var delta = TimeSpan.FromMilliseconds(1000);
var connectionPolicy = new ConnectionPolicy()
{
ConnectionMode = ConnectionMode.Direct,
ConnectionProtocol = Protocol.Tcp
};
var client = new DocumentClient(new Uri(endpointUrl), authKey, connectionPolicy).AsReliable(new ExponentialBackoff(3, min, max, delta));
Task result = client.OpenAsync();
result.Wait();
Client = client;
}
}
And here is the code for the Put handler in my Web API class:
public class InstallationController : ApiController
{
private IReliableReadWriteDocumentClient docdb;
private string docdbUri;
public InstallationController()
{
docdb = Documents.Instance.Client;
var databaseId = ConfigurationManager.AppSettings["Microsoft.Azure.DocumentDb.DatabaseId"];
var collectionName = ConfigurationManager.AppSettings["Microsoft.Azure.DocumentDb.CollectionName"];
docdbUri = "dbs/" + databaseId + "/colls/" + collectionName;
}
// PUT api/installation/<installationId>
// This creates or updates an installation
public async Task<IHttpActionResult> Put(string id, DeviceInstallation deviceUpdate)
{
string message;
var telemetryClient = new TelemetryClient();
if (id != deviceUpdate.Id)
{
return BadRequest();
}
// Code to check for existing record with same APNS Token omitted for clarity
var upsertResponse = await docdb.UpsertDocumentAsync(docdbUri, deviceUpdate);
requestCharge = upsertResponse.RequestCharge;
message = string.Format("Request charge for installation upsert: {0}", requestCharge);
telemetryClient.TrackTrace(message);
// Code to save installation to notification hub omitted for clarity
return Ok();
}
}

