I have a method that we call to get the reference to the CloudTable
before I write or query table storage.
private static CloudTable GetCloudTable() {
var storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
var tableClient = storageAccount.CreateCloudTableClient();
var table = tableClient.GetTableReference("TheTableName");
return table;
}
Is acceptable to put this in the constructor of my table handling class? Is it an additional overhead to run this code on every table insert? It seems to me that I am increasing the number of transactions that I am running.
Azure Storage Table was not created by God, it was created by folks like us (much smarter though). It has limitations on size of a single row (1 MB), size of a single column (64KB), number of columns per row (255) and so on.
An entity in Azure Storage can be up to 1MB in size. An entity in Azure Cosmos DB can be up to 2MB in size. Properties: A property is a name-value pair. Each entity can include up to 252 properties to store data.
Azure Table Storage supports a single region with an optional read-only secondary region for availability. Cosmos DB supports distribution from 1 to more than 30 regions with automatic failovers worldwide. You can easily manage this from the Azure portal and define the failover behavior.
Your code snippets does not make any message to be sent to the Storage Service. The actual message is sent only when you use the "table" variable to actually Create, Query, or perform any CRUD operation against the storage. So the answer to "am I increasing the number of transactions by running this code on every table insert?" is NO.
That said, CloudStorageAccount.Parse and CloudConfigurationManager.GetSetting (the first line in your code snippet) do create some overhead (string parsing and configuration item retrieving). So for sure I suggest you to perform them only once and then reuse their result in every table operation(yes, putting this in the constructor IS an option).
However, the CloudTableClient object returned by CreateCloudTableClient() is not guaranteed to be thread safe. So IF threading is a issue in your evnvironment (i.e. you are you are using the same instance of your class from multple threads), I suggest to create a new instance of CloudTableClient every time you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With