Esempio n. 1
0
        static void Main()
        {
            // This sample shows the use of FASTER as a concurrent pure in-memory cache

            var log = new NullDevice(); // no storage involved

            // Define settings for log
            var logSettings = new LogSettings
            {
                LogDevice       = log, ObjectLogDevice = log,
                MutableFraction = 0.9,                          // 10% of memory log is "read-only region"
                CopyReadsToTail = CopyReadsToTail.FromReadOnly, // reads in read-only region are copied to tail
                PageSizeBits    = 14,                           // Each page is sized at 2^14 bytes
                MemorySizeBits  = 25,                           // (2^25 / 24) = ~1.39M key-value pairs (log uses 24 bytes per KV pair)
            };

            // Number of records in memory, assuming class keys and values and x64 platform
            // (8-byte key + 8-byte value + 8-byte header = 24 bytes per record)
            int numRecords = (int)(Math.Pow(2, logSettings.MemorySizeBits) / 24);

            // Targeting 1 record per bucket
            var numBucketBits = (int)Math.Ceiling(Math.Log2(numRecords));

            h           = new FasterKV <CacheKey, CacheValue>(1L << numBucketBits, logSettings, comparer: new CacheKey());
            sizeTracker = new CacheSizeTracker(h, logSettings.MemorySizeBits);

            PopulateStore(numRecords);
            ContinuousRandomWorkload();

            h.Dispose();

            Console.WriteLine("Press <ENTER> to end");
            Console.ReadLine();
        }
 public AddressSpace(Machine m, int addrSpaceShift, int pageShift)
 {
     this.machine = m;
     this.addrSpaceSize = 1 << addrSpaceShift;
     this.addrSpaceMask = addrSpaceSize - 1;
     this.pageShift = pageShift;
     this.pageSize = 1 << pageShift;
     this.memoryMap = new IDevice[addrSpaceSize / pageSize];
     IDevice nullDev = new NullDevice();
     for (int pageno=0; pageno < PageCount; ++pageno)
         memoryMap[pageno] = nullDev;
 }
        public override Maybe<string> Validate()
        {
            var result = base.Validate();

            if (result)
            {
                if (Streams.Any(s => !s.SampleRate.Equals(SampleRate)))
                    return Maybe<string>.No("All streams must have the same sample rate as controller.");

                if (SampleRate == null)
                    return Maybe<string>.No("Sample rate required.");

                if (SampleRate.BaseUnits.ToLower() != "hz")
                    return Maybe<string>.No("Sample rate must be in Hz.");

                if (SampleRate.QuantityInBaseUnits <= 0)
                    return Maybe<string>.No("Sample rate must be greater than 0");

                if (!ActiveStreams.Any())
                    return Maybe<string>.No("Must have at least one active stream (a stream with an associated device)");

                // This is a workaround for issue #41 (https://github.com/Symphony-DAS/Symphony/issues/41)
                foreach (var s in InputStreams)
                {
                    foreach (var ed in s.Devices.OfType<NullDevice>().ToList())
                    {
                        s.RemoveDevice(ed);
                    }
                }

                if (Math.Max(ActiveOutputStreams.Count(), ActiveInputStreams.Count()) >= 1)
                {
                    var samplingInterval = 1e9m / (SampleRate.QuantityInBaseUnits * Math.Max(ActiveOutputStreams.Count(), ActiveInputStreams.Count()));

                    while (samplingInterval % Device.DeviceInfo.MinimumSamplingStep != 0m)
                    {
                        var inactive = InputStreams.Where(s => !s.Active).ToList();

                        if (!inactive.Any())
                            return Maybe<string>.No("A well-aligned sampling interval is not possible with the current sampling rate");

                        var dev = new NullDevice();
                        dev.BindStream(inactive.First());

                        samplingInterval = 1e9m / (SampleRate.QuantityInBaseUnits * Math.Max(ActiveOutputStreams.Count(), ActiveInputStreams.Count()));
                    }
                }
            }

            return result;
        }