Beispiel #1
0
        public static Sampler NewSampler()
        {
            Sampler sampler = YCSBClientExecutor.NewSampler();

            foreach (string cons in slas.Keys)
            {
                sampler.AddSampleName(cons + "Latency", Sampler.OutputType.Average);
                sampler.AddSampleName(cons + "PrimaryAccesses", Sampler.OutputType.Total);
                sampler.AddSampleName(cons + "TotalAccesses", Sampler.OutputType.Total);
            }
            return(sampler);
        }
Beispiel #2
0
        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);
        }