public static void Main(string[] args) { Process currProc = Process.GetCurrentProcess(); containerName = "testcontainer"; //Guid.NewGuid().ToString("N").ToLower(); if (args.Length == 0) { args = new string[7]; // the number of test iterations args[0] = "1"; // the number of blobs args[1] = "10"; // the number of concurrent test workers. args[2] = "2"; // the blob size in KB args[3] = "1024"; // the number of parallel requests per blob args[4] = "1"; // use https or not args[5] = "false"; // the result folder name args[6] = "folder1"; } iterations = Int32.Parse(args[0]); blobs = Int32.Parse(args[1]); concurrency = Int32.Parse(args[2]); blobSizeInKB = Int32.Parse(args[3]); parallelRequestsPerBlob = Int32.Parse(args[4]); useHttps = bool.Parse(args[5]); resultFileFolderName = args[6]; if (!Directory.Exists(resultFileFolderName)) { Directory.CreateDirectory(resultFileFolderName); } resultFile = string.Format(@"{6}\{0}_{1}_{2}_{3}_{4}_{5}.csv", blobSizeInKB, parallelRequestsPerBlob, concurrency, useHttps, iterations, blobs, resultFileFolderName); ThreadPool.SetMinThreads(concurrency * parallelRequestsPerBlob, concurrency * parallelRequestsPerBlob); accounts = Account.GetStorageAccounts(useHttps); ClientRegistry.Init(accounts, accounts[configAccountName]); configuration = new ReplicaConfiguration(containerName); ClientRegistry.AddConfiguration(configuration); if (firstClient) { // delete configuration blob and tables // ReplicaConfiguration.DeleteConfiguration(containerName); ConfigurationCloudStore backingStore = new ConfigurationCloudStore(accounts[configAccountName], configuration); backingStore.DeleteConfiguration(); CloudTableClient ConfigurationCloudTableClient = accounts[configAccountName].CreateCloudTableClient(); CloudTable slaTable = ConfigurationCloudTableClient.GetTableReference(ConstPool.SLA_CONFIGURATION_TABLE_NAME); slaTable.DeleteIfExists(); slaTable = ConfigurationCloudTableClient.GetTableReference(ConstPool.SESSION_STATE_CONFIGURATION_TABLE_NAME); slaTable.DeleteIfExists(); Console.WriteLine("removed everything, wait 40 seconds ..."); Thread.Sleep(40000); // recreate configuration configuration.PrimaryServers.Add("dbtsouthstorage"); configuration.SyncWithCloud(accounts[configAccountName], false); Console.WriteLine("recreated configuration, wait 10 seconds ..."); Thread.Sleep(10000); } else { // retrieve configuration from cloud configuration.SyncWithCloud(accounts[configAccountName]); } if (firstClient) { slaEngine = new ConsistencySLAEngine(CreateShoppingCartSla1(), configuration); } else { slaEngine = new ConsistencySLAEngine(CreateShoppingCartSla2(), configuration); } blobClient = accounts["dbtsouthstorage"].CreateCloudBlobClient(); blobContainer = blobClient.GetContainerReference(containerName); blobContainer.CreateIfNotExists(); capContainer = new CapCloudBlobContainer(blobContainer); // Generate random data BlobDataBuffer = new byte[1024 * blobSizeInKB]; Random random = new Random(); random.NextBytes(BlobDataBuffer); //ServiceLevelAgreement sla = CreateShoppingCartSla(); Stopwatch totalWatch = new Stopwatch(); totalWatch.Start(); for (int m = 0; m < concurrency; m++) { ThreadPool.QueueUserWorkItem((o) => { Interlocked.Increment(ref concurrentWorkers); for (int i = 0; i < iterations; i++) { Console.WriteLine("Running thread " + m + "." + i); Console.WriteLine("concurrent workers: " + concurrentWorkers); try { // do upload blob test. var blobsList = UploadBlob(); Console.WriteLine("Upload Finished ...\n"); // GET and DELETE. DoGetAndDelete(blobsList); Console.WriteLine("DoGetAndDelete Finished ...\n"); configure("client", containerName); Console.WriteLine("Configure Finished ...\n"); } catch (Exception e) { Console.WriteLine(e.ToString()); } } Interlocked.Decrement(ref concurrentWorkers); }); } Console.WriteLine("Program: Started to sleep"); Thread.Sleep(5000); while (Interlocked.CompareExchange(ref concurrentWorkers, -1, 0) != -1) { if (concurrentWorkers < 0) { break; } Console.WriteLine("Waiting for a thread because there are " + concurrentWorkers + " threads."); Thread.Sleep(5000); } Console.WriteLine("Finished execution. "); ClientRegistry.GetConfigurationContainer(containerName).Delete(); blobContainer.DeleteIfExists(); totalWatch.Stop(); long totalTimeTaken = totalWatch.ElapsedMilliseconds; using (StreamWriter sw = new StreamWriter(resultFile)) { sw.Write(String.Format("Total time taken to run the test in ms : {0}\n\n", totalTimeTaken)); sw.Write(String.Format("Args:Concurrency: {0} BlobSizeInKB:{1} ParallelRequestsPerBlob:{2} UsingHttps:{3} \n", concurrency, blobSizeInKB, parallelRequestsPerBlob, useHttps)); // display result DisplayResults(sw, "Insert", insertTimes); DisplayResults(sw, "Get", getTimes); DisplayResults(sw, "Delete", deleteTimes); float tmp = 0; foreach (SubSLA s in capContainer.SLA) { tmp += s.Utility * s.NumberOfHits; } sw.Write(String.Format("Current utility ", tmp)); // Display perf results PerfMetrics metrics = new PerfMetrics(); metrics.Update(currProc); metrics.Print(sw); } Console.Read(); }
/// <summary> /// Trys to acquire the lease on the configuration blob. /// Note that the caller must check HasLease to see whether the acquisition succeeded. /// </summary> /// <param name="containerName">Name of the container/configuration</param> /// <param name="policy">Whether to try once or many times</param> /// <returns>An instance of the CloudBlobLease object.</returns> public CloudBlobLease(string containerName, LeaseTakingPolicy policy) { this.blob = ClientRegistry.GetConfigurationContainer(containerName).GetBlockBlobReference(ConstPool.CURRENT_CONFIGURATION_BLOB_NAME); AcquireBlobLease(policy); }