public static void Initialize() { // get list of Azure storage accounts accounts = PileusApp.Account.GetStorageAccounts(false); ClientRegistry.Init(accounts, accounts[configStorageSite]); // delete cloud configuration if desired if (clearConfiguration) { ReplicaConfiguration configToDelete = new ReplicaConfiguration(containerName); ConfigurationCloudStore backingStore = new ConfigurationCloudStore(accounts[configStorageSite], configToDelete); Log("Deleting configuration in Azure..."); backingStore.DeleteConfiguration(); Log("Done. Now waiting for it to really take effect..."); Thread.Sleep(40000); // give system a chance to complete delete } // read/create configuration Log("Creating/reading configuration..."); config = new ReplicaConfiguration(containerName, PrimaryServers, SecondaryServers, NonReplicaServers, ReadOnlySecondaryServers, cloudBackedConfiguration, stableConfiguration); ClientRegistry.AddConfiguration(config); // upload data into containers if desired if (reloadDatabase) { CreateDatabase(numBlobs); } // create SLAs slas = new Dictionary <string, ServiceLevelAgreement>(); slas["strong"] = CreateConsistencySla(Consistency.Strong); slas["causal"] = CreateConsistencySla(Consistency.Causal); slas["bounded"] = CreateBoundedConsistencySla(boundInSeconds); slas["readmywrites"] = CreateConsistencySla(Consistency.ReadMyWrites); slas["monotonic"] = CreateConsistencySla(Consistency.MonotonicReads); slas["eventual"] = CreateConsistencySla(Consistency.Eventual); currentSLA = CreateFastOrStrongSla(); slas["sla"] = currentSLA; // get/create replicated container Log("Creating replicated container..."); Dictionary <string, CloudBlobContainer> containers = new Dictionary <string, CloudBlobContainer>(); foreach (string site in accounts.Keys) { CloudBlobClient blobClient = accounts[site].CreateCloudBlobClient(); CloudBlobContainer blobContainer = blobClient.GetContainerReference(containerName); blobContainer.CreateIfNotExists(); containers.Add(site, blobContainer); } container = new CapCloudBlobContainer(containers, PrimaryServers.First()); container.Configuration = config; container.Monitor = new ServerMonitor(config); configurator = new Configurator(containerName); }
public static long DeleteBlob(string blobName, CapCloudBlobContainer cont) { Stopwatch watch = new Stopwatch(); watch.Start(); ICloudBlob blob = cont.GetBlobReference(blobName); blob.Delete(); watch.Stop(); return(watch.ElapsedMilliseconds); }
public static long PutBlob(string blobName, byte[] data, CapCloudBlobContainer cont) { Stopwatch watch = new Stopwatch(); watch.Start(); ICloudBlob blob = cont.GetBlobReference(blobName); using (var ms = new MemoryStream(data)) { blob.UploadFromStream(ms); } watch.Stop(); return(watch.ElapsedMilliseconds); }
public static long GetBlob(string blobName, CapCloudBlobContainer cont) { Stopwatch watch = new Stopwatch(); watch.Start(); ICloudBlob blob = cont.GetBlobReference(blobName); using (MemoryStream ms = new MemoryStream()) { blob.DownloadToStream(ms); } watch.Stop(); return(watch.ElapsedMilliseconds); }
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(); }