When you want to create a collection in your Azure DocumentDB database account, you have to estimate and specify the throughput size and Azure DocumentDB reserves resources to satisfy your application throughput’s needs. You have to pay for the reserved resources allocated to your collection regardless of usage and the is why it’s important to estimate the throughput size correctly to reduce the operation costs.
What is the throughput measure unit?
Request Unit (RU) per second is the unit of throughput measurement. Azure reserves specified amount of RU/S as your collection throughput. A single request unit represents the processing capacity required to read a single 1KB document. Depends on your document, other requests such as create, update and delete consume more request units.
How to measure throughput size ?
As a first step it’s always good to start with default throughout size. and then start monitoring and measuring consumed request units for common operations and adjust the throughput size. When you query against a collection, Azure returns request charge value in portal or through x-ms-request-charge response header in code. Therefore, you can get some ideas about cost of your queries.
Many factors are involved in request unit measurement. Things like number of document properties, indexes, document size and data consistency. Therefore, RU cost differs from application to another application. When you have an idea about your application queries costs and estimated number of requests per second you can estimate how much throughput you need to satisfy your application needs.
One of the best methods to monitor your service performance and consumed RUs is to set alarms. You can define as many types of alarm as you want to make sure reserved throughput is enough but not more than enough. As a case in point, you can monitor throttled requests number to make sure enough resources has been allocated or check consumed request units to make sure your are not allocating more than enough. If you are keep getting notifications about not consuming expected RUs then it’s time to scale down.
When you create a document in Azure DocumentDB, regardless of properties in the document, Azure creates and populates some default properties behind the scene for the document. Here is a brief overview of document properties:
_RID: Indicates unique resource identifier. Each document in Azure DocumentDB must have a unique string identifier (across the collection) which can be changed over the time and is specified in the document; However, _RID is generated by Azure and cannot be changed over the time.
_TS: Indicates the last time when document gets modified. Azure updates the value when you modify the document. This can be very useful for your application to get latest changes and updates after specific date.
_SELF: Unique addressable URI of the resource. Here is an example of the _SELF link: dbs/DppTAA==/colls/DppTAvdAA=/docs/DppTAMYvdAABAAAAAAA==/
As you can see it starts with dbs and database Resource ID and then Colls and the collection Resource ID and finally docs and the document _RID identifier.
_ETAG: _ETAGs are used by Azure to manage optimistic concurrency and avoid users override each others’ changes. Stas Kondratyev posted a comprehensive article about _ETAGS here.
_ATTACHMENTS: Indicates path to the document’s attachment.
How to get Document Properties ?
To get the document properties, you need to select the document you want from the collection and then click on Properties icon on Document blade and you can get all the properties in Properties blade.
Sometimes you need to debug your application in cloud environment (well, I don’t like to say production environment !) to reproduce a bug or test your application against cloud environment data. Azure Web App remote debugging is painless and sweat. The only thing you need is just to attach debugger to your application. To attach debugger, right click on the Web App name and choose Attach debugger from context menu or actions bar:
Things to remember:
When you attach debugger and pause for breakpoint, you stop all requests to your application. Therefore, you should not debug your application in Production environment. Staging environment is one of the best remote debugger friends although.
If debugging takes time and app is stopped for a few minutes, Azure treats your website worker process as unresponsive and will try to restart it; Therefore, you need to be quick.