public static void ReadDataFile(Sampler sampler) { int lines = 0; bool endOfFile = false; if (readDataFromFile && File.Exists(samplerFileName)) { using (TextReader file = File.OpenText(samplerFileName)) { do { foreach (string cons in slas.Keys) { string line = file.ReadLine(); if (line == null) { endOfFile = true; } else { sampler.AddSample(cons + "Latency", float.Parse(line)); lines++; } } }while (!endOfFile); } } Log("Read " + lines + " samples"); }
/* * public static ServiceLevelAgreement CreateShoppingCartSla1() * { * ServiceLevelAgreement sla = new ServiceLevelAgreement(""+1); * SubSLA subSla1 = new SubSLA(130, Consistency.Strong, 0, 1); * SubSLA subSla2 = new SubSLA(130, Consistency.ReadMyWrites, 0, .70f); * SubSLA subSla3 = new SubSLA(250, Consistency.Eventual, 0, 0.5f); * SubSLA subSla4 = new SubSLA(500, Consistency.Eventual, 0, 0.05f); * sla.Add(subSla1); * sla.Add(subSla2); * sla.Add(subSla3); * sla.Add(subSla4); * return sla; * } */ #region Client public static void RunClient(int tick) { Interlocked.Increment(ref concurrentWorkers); byte[] BlobDataBuffer = new byte[blobSizeInB]; Random random = new Random(); random.NextBytes(BlobDataBuffer); Dictionary <string, CloudStorageAccount> accounts = Account.GetStorageAccounts(false); blobClient = accounts[testSite].CreateCloudBlobClient(); container = blobClient.GetContainerReference(containerName); container.CreateIfNotExists(); try { YCSBWorkload workload = new YCSBWorkload(workloadType, 100); YCSBOperation op = workload.GetNextOperation(); while (op != null) { long duration = 0; ICloudBlob blob = container.GetBlobReferenceFromServer(op.KeyName); if (op.Type == YCSBOperationType.READ) { duration = GetBlob(blob); if (PileusAppConstPool.ENABLE_CLIENT_READWRITE_OUTPUT) { Console.WriteLine("Performed Read for " + op.KeyName + " in " + duration); } sampler.AddSample("ReadCount", 1); sampler.AddSample("ReadLatency", duration); sampler.AddSample("concurrentWorkers", concurrentWorkers); } else if (op.Type == YCSBOperationType.UPDATE) { random.NextBytes(BlobDataBuffer); duration = PutBlob(blob, BlobDataBuffer); if (PileusAppConstPool.ENABLE_CLIENT_READWRITE_OUTPUT) { Console.WriteLine("Performed Write for " + op.KeyName + " in " + duration); } sampler.AddSample("WriteCount", 1); sampler.AddSample("WriteLatency", duration); sampler.AddSample("concurrentWorkers", concurrentWorkers); } op = workload.GetNextOperation(); } if (PileusAppConstPool.ENABLE_CLIENT_READWRITE_OUTPUT) { Console.WriteLine("Client Finished ...\n"); } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } Interlocked.Decrement(ref concurrentWorkers); if (((concurrentClientsPerTick - 1) >= concurrentWorkers) && (currentTick < totalExperimentLength)) { //We want to keep total number of concurrent workers (i.e., concurrentWorkers) equals to "concurrentClientsPerTick". additionalCreatedClientsPerTick++; RunClient(currentTick); } }
public static Sampler PerformReadsWritesSyncs(Sampler reuseSampler = null, bool recon = false) { YCSBWorkload workload = new YCSBWorkload(YCSBWorkloadType.Workload_a, numBlobsToUse); sampler = reuseSampler; if (sampler == null) { sampler = NewSampler(); } byte[] BlobDataBuffer = new byte[1024]; Random random = new Random(); random.NextBytes(BlobDataBuffer); // Synchronize before we start the experiment if (startExperiment == true) { Log("Syncing data to secondary replicas..."); SyncSecondaryServers(); startExperiment = false; } for (int ops = 0; ops < numReadWrites; ops++) { YCSBOperation op = workload.GetNextOperation(); if (op == null) { // exhasted trace so get new one workload = new YCSBWorkload(YCSBWorkloadType.Workload_a, numBlobsToUse); op = workload.GetNextOperation(); } long duration = 0; if (op.Type == YCSBOperationType.READ) { // HACK: warm up the primary server cache the first time we access it // Reason: Strong pays higher latency compared to later consistencies in "containers" because of cold misses. //duration = YCSBClientExecutor.GetBlob(op.KeyName, containers["eventual"]); //duration = YCSBClientExecutor.GetBlob(op.KeyName, containers["strong"]); List <string> consInRandomOrder = slas.Keys.OrderBy(el => random.Next()).ToList(); foreach (string cons in consInRandomOrder) { CapCloudBlob blob = (CapCloudBlob)container.GetBlobReference(op.KeyName, cons); blob.Sla = slas[cons]; // executing GetBlob twice substantially reduces the latency variance //duration = YCSBClientExecutor.GetBlob(blob); duration = YCSBClientExecutor.GetBlob(blob); sampler.AddSample(cons + "Latency", duration); sampler.AddSample(cons + "TotalAccesses", 1); if (config.PrimaryServers.Contains(blob.engine.chosenServer.Name)) { sampler.AddSample(cons + "PrimaryAccesses", 1); } Log("Performed " + cons + " read for " + op.KeyName + " in " + duration + " from " + SiteName(blob.engine.chosenServer.Name)); //AppendDataFile(duration); if (cons == "sla") { foreach (SubSLA sub in slas[cons]) { Log("SLA: " + sub.Consistency + " hits=" + sub.NumberOfHits + " misses=" + sub.NumberOfMisses); } } } sampler.AddSample("ReadCount", 1); } else if (op.Type == YCSBOperationType.UPDATE) { random.NextBytes(BlobDataBuffer); // use write with multiple sessions to avoid duplicate writes to primary List <SessionState> sessions = new List <SessionState>(); foreach (string cons in slas.Keys) { sessions.Add(container.GetSession(cons)); } ReadWriteFramework protocol = new ReadWriteFramework(op.KeyName, config, null); Stopwatch watch = new Stopwatch(); using (var ms = new MemoryStream(BlobDataBuffer)) { AccessCondition ac = AccessCondition.GenerateEmptyCondition(); watch.Start(); protocol.Write(blob => blob.UploadFromStream(ms, ac), ac, sessions, container.Monitor); } duration = watch.ElapsedMilliseconds; /* * foreach (string cons in slas.Keys) * { * ICloudBlob blob = container.GetBlobReference(op.KeyName, cons); * duration = YCSBClientExecutor.PutBlob(blob, BlobDataBuffer); * Log("Performed " + cons + " write for " + op.KeyName + " in " + duration); * } */ Log("Performed " + " write for " + op.KeyName + " in " + duration); sampler.AddSample("WriteCount", 1); sampler.AddSample("WriteLatency", duration); } if (++opsSinceSync >= opsBetweenSyncs) { Log("Syncing data to secondary replicas..."); SyncSecondaryServers(); opsSinceSync = 0; } } return(sampler); }