Beispiel #1
0
        public void AllToTapeTest()
        {
            var events = ServiceManager.Kernel.Get<IEventManager>().GetAll();
            SimplexDecision allocation = new SimplexDecision()
            {
                Memory = 0,
                Disk = 0,
                Tape = 100000
            };
            _simplex.AssignEvents(allocation, events);

            foreach (Event e in events)
            {
                Assert.AreEqual(FooCDNAccessor.StorageType.Tape, e.StorageLocation);
            }
        }
Beispiel #2
0
 public bool CheckCost(SimplexDecision allocations, double numViews)
 {
     //rounding in case cost is 15.00000000001 (floating point silliness)
     return Math.Round((0.25 + 0.3 * numViews) * allocations.Memory + (0.025 + 0.1 * numViews) * allocations.Disk, 2) <= 15;
 }
Beispiel #3
0
        public void AssignEvents(SimplexDecision allocation, IEnumerable<Event> events)
        {
            Dictionary<Event, double> eventViews = new Dictionary<Event, double>();

            foreach (Event e in events)
            {
                eventViews.Add(e, EstimateViewCount(e));
            }

            eventViews = eventViews.OrderByDescending(d => d.Value) as Dictionary<Event, double>;

            var averageStoragePerUser = GetStoragePerUser(events);

            double sizeNeeded;
            foreach (Event e in events)
            {
                if (e.EndTime < DateTime.Now)
                {
                    sizeNeeded = GetEventStorageSize(e);
                }
                else if (e.StartTime > DateTime.Now && e.StartTime < DateTime.Now.AddDays(1))
                {
                    sizeNeeded = e.Guests.Count * averageStoragePerUser;
                }
                else
                {
                    sizeNeeded = 0;
                }

                if (allocation.Memory > sizeNeeded)
                {
                    allocation.Memory -= sizeNeeded;
                    e.StorageLocation = FooCDNAccessor.StorageType.MemCache;
                }
                else if(allocation.Disk > sizeNeeded)
                {
                    allocation.Disk -= sizeNeeded;
                    e.StorageLocation = FooCDNAccessor.StorageType.Disk;
                }
                else
                {
                    //NOTE: tape can be less than 0, if events did not fit evenly into memory/disk
                    allocation.Tape -= sizeNeeded;
                    e.StorageLocation = FooCDNAccessor.StorageType.Tape;
                }

                var result = ServiceManager.Kernel.Get<IEventManager>().Save(e);

                if(!result.Success)
                {
                    throw new Exception("Error saving event by simplex allocator");
                }
            }

            foreach (Event e in events)
            {
                foreach (Post p in e.Posts)
                {
                    if (p.BlobId != null)
                    {
                        ServiceManager.Kernel.Get<IFooCDNManager>().Put(((Post)p).BlobId, e.StorageLocation);
                    }
                }
            }
        }