示例#1
0
        void Populate(ISortedDictionary <string, object> Store)
        {
            for (int i = 0; i < MaxCount; i++)
            {
                int    pid   = (int)Store.GetNextSequence();
                string key   = string.Empty;
                object value = null;
                switch (i % 4)
                {
                case 0:
                    key   = string.Format("PersonBlob{0}", pid);
                    value = new PersonBlob
                    {
                        Blob = new byte[PersonBlob.BlobAvgSize]
                    };
                    break;

                case 1:
                    key   = string.Format("Person{0}", pid);
                    value = new Person
                    {
                        FirstName = string.Format("Joe {0}", pid),
                        LastName  = string.Format("Curly {0}", pid)
                    };
                    break;

                case 2:
                    key   = string.Format("Address{0}", pid);
                    value = new Address
                    {
                        Street  = string.Format("123 Love Lane {0}", pid),
                        City    = "Fremont",
                        State   = "California",
                        Country = "U.S.A.",
                        ZipCode = 94599
                    };
                    break;

                case 3:
                    key   = string.Format("Dept{0}", pid);
                    value = new Department
                    {
                        Id   = pid,
                        Name = string.Format("Dept {0}", pid)
                    };
                    break;
                }
                Store.Add(key, value);
                if (i % 2000 == 0)
                {
                    Store.Flush();
                }
            }
        }
示例#2
0
        private void Populate(ISortedDictionary <PersonKey, Person> PeopleStore,
                              ISortedDictionary <int, Address> AddressStore, int MaxCount)
        {
            int[] AddressIDs        = new int[AddressBatchCount];
            int   AddressBatchIndex = 0;

            // insert Person and Address records onto PeopleStore and AddressStore in batch (bulk insert!)
            for (int i = 1; i <= MaxCount; i++)
            {
                Address addr = new Address();
                addr.AddressID = (int)AddressStore.GetNextSequence();
                addr.City      = "Fremont";
                addr.Country   = "USA";
                addr.State     = "California";
                addr.Street    = string.Format("143{0} LoveLane", i);
                addr.ZipCode   = "99999";
                AddressStore.Add(addr.AddressID, addr);

                AddressIDs[AddressBatchIndex++] = addr.AddressID;
                //** in this block we've caused People to be inserted in batch of 1000
                if (AddressBatchIndex == AddressBatchCount)
                {
                    //** insert People in batch of 1000
                    int PhoneCtr = 1000;
                    for (int AddressID = 0; AddressID < AddressIDs.Length; AddressID++)
                    {
                        Person p = new Person();
                        p.AddressID   = AddressIDs[AddressID];
                        p.FirstName   = string.Format("{0}Joe", p.AddressID);
                        p.LastName    = "Peter";
                        p.PhoneNumber = string.Format("510-555-{0}", PhoneCtr++);
                        PeopleStore.Add(p.GetKey(), p);
                    }
                    AddressBatchIndex = 0;
                }
            }
            // if last batch wasn't inserted yet, then insert it
            if (AddressBatchIndex > 0)
            {
                for (int AddressID = 0; AddressID < AddressBatchIndex; AddressID++)
                {
                    Person p = new Person();
                    p.AddressID   = AddressIDs[AddressID];
                    p.FirstName   = string.Format("Joe{0}", p.AddressID);
                    p.LastName    = "Peter";
                    p.PhoneNumber = "510-555-9999";
                    PeopleStore.Add(p.GetKey(), p);
                }
            }
        }
        void Populate(ISortedDictionary <object, object> PeopleStore)
        {
            int ZipCodeCtr = 5000;

            CacheRecord[] BatchedRecords = new CacheRecord[BatchCount];
            int           BatchedIndex   = 0;

            for (int i = 0; i < MaxCount; i++)
            {
                int    pid = (int)PeopleStore.GetNextSequence();
                Person p   = new Person()
                {
                    FirstName = string.Format("Joe{0}", pid),
                    LastName  = string.Format("Peter{0}", pid)
                };
                BatchedRecords[BatchedIndex] = new CacheRecord()
                {
                    p    = p,
                    blob = new PersonBlob
                    {
                        Blob = new byte[PersonBlob.BlobAvgSize]
                    }
                };
                BatchedRecords[BatchedIndex].blob.Blob[0] = 1;
                BatchedRecords[BatchedIndex].blob.Blob[5] = 54;
                BatchedIndex++;
                if (BatchedIndex == BatchCount)
                {
                    for (int i2 = 0; i2 < BatchedIndex; i2++)
                    {
                        PeopleStore.Add(BatchedRecords[i2].p, BatchedRecords[i2].blob);
                    }
                    PeopleStore.Flush();
                    if (i % 500 == 0)
                    {
                        ZipCodeCtr++;
                    }
                    BatchedIndex = 0;
                }
            }
            if (BatchedIndex > 0)
            {
                for (int i2 = 0; i2 < BatchedIndex; i2++)
                {
                    PeopleStore.Add(BatchedRecords[i2].p, BatchedRecords[i2].blob);
                }
                PeopleStore.Flush();
            }
        }
示例#4
0
        void Populate(ObjectServer server,
                      ISortedDictionary <long, Person> PeopleStore,
                      int maxCount,
                      int seed
                      )
        {
            int ZipCodeCtr = 5000;

            for (int i = seed; i < maxCount; i++)
            {
                if (i == maxCount - 2)
                {
                    object o = 90;
                }
                int     aid  = i;
                Address addr = new Address()
                {
                    AddressID = aid,
                    Key       = new AddressKey()
                    {
                        Street  = string.Format("143{0} LoveLane", aid),
                        City    = "Fremont",
                        Country = "USA",
                        State   = "California",
                        ZipCode = ZipCodeCtr.ToString()
                    }
                };
                int    pid = (int)PeopleStore.GetNextSequence();
                Person p   = new Person()
                {
                    PersonID  = pid,
                    AddressID = addr.AddressID,
                    Key       = new PersonKey()
                    {
                        FirstName = string.Format("Joe{0}", pid),
                        LastName  = string.Format("Peter{0}", pid)
                    },
                    PhoneNumber = "510-555-9999"
                };
                PeopleStore.Add(p.PersonID, p);
                if (i % 5000 == 0)
                {
                    ZipCodeCtr++;
                    PeopleStore.Flush();
                }
            }
        }
示例#5
0
 void Populate(ISortedDictionary <long, Person> PeopleStore)
 {
     for (int i = 0; i < MaxCount; i++)
     {
         int    pid = (int)PeopleStore.GetNextSequence();
         Person p   = new Person()
         {
             PersonID = pid,
             Key      = new PersonKey()
             {
                 FirstName = string.Format("Joe{0}", pid),
                 LastName  = string.Format("Peter{0}", pid)
             },
             PhoneNumber = "510-555-9999"
         };
         PeopleStore.Add(p.PersonID, p);
     }
 }
示例#6
0
        void Populate(ISortedDictionary <int, Person> PeopleStore,
                      ISortedDictionary <int, Address> AddressStore, int MaxCount)
        {
            Person[] NewPeople      = new Person[1000];
            int      NewPeopleIndex = 0;

            for (int i = 0; i < MaxCount; i++)
            {
                Address addr = new Address();
                addr.AddressID = (int)AddressStore.GetNextSequence();
                addr.City      = "Fremont";
                addr.Country   = "USA";
                addr.State     = "California";
                addr.Street    = string.Format("143{0} LoveLane", i);
                addr.ZipCode   = "99999";
                AddressStore.Add(addr.AddressID, addr);

                Person p = new Person();
                p.AddressID   = addr.AddressID;
                p.FirstName   = string.Format("Joe{0}", i);
                p.LastName    = "Peter";
                p.PhoneNumber = "510-555-9999";
                NewPeople[NewPeopleIndex++] = p;
                //** Batch add New People each set of 1000
                if (NewPeopleIndex == 1000)
                {
                    foreach (Person np in NewPeople)
                    {
                        PeopleStore.Add((int)PeopleStore.CurrentSequence, np);
                    }
                    NewPeopleIndex = 0;
                }
            }
            //** add any left over new People haven't been added yet...
            if (NewPeopleIndex > 0)
            {
                for (int i2 = 0; i2 < NewPeopleIndex; i2++)
                {
                    Person np = NewPeople[i2];
                    PeopleStore.Add((int)PeopleStore.CurrentSequence, np);
                }
                NewPeopleIndex = 0;
            }
        }
示例#7
0
        void Stress(ISortedDictionary <int, Person> PeopleStore,
                    ISortedDictionary <int, Address> AddressStore, int MaxCount)
        {
            PeopleStore.HintBatchCount  = 100;
            AddressStore.HintBatchCount = 100;
            PeopleStore.MoveLast();
            int    mx  = MaxCount;
            Random rdm = new Random(mx);

            //** NOTE: no batching implemented here, just basic operations...
            //** see Populate function how to do batch Add in set of 1000 which optimizes SOP/Disk buffer usage
            //** batch remove can also be done to optimize usage of such buffers & minimize file pointer jumps.
            for (int i = 0; i < MaxCount / 10; i++)
            {
                int    no = rdm.Next(mx);
                Person p;

                if (i % 2 == 0)
                {
                    Address addr = new Address();
                    addr.AddressID = (int)AddressStore.GetNextSequence();
                    addr.City      = "Fremont";
                    addr.Country   = "USA";
                    addr.State     = "California";
                    addr.Street    = string.Format("143{0} LoveLane", i);
                    addr.ZipCode   = "99999";
                    AddressStore.Add(addr.AddressID, addr);

                    p           = new Person();
                    p.AddressID = addr.AddressID;
                    int i2 = no;
                    p.FirstName   = string.Format("Joe{0}", i2);
                    p.LastName    = "Peter";
                    p.PhoneNumber = "510-555-9999";
                    PeopleStore.Add(i2, p);
                }
                else
                {
                    if (PeopleStore.TryGetValue(no, out p))
                    {
                        AddressStore.Remove(p.AddressID);
                        PeopleStore.Remove(no);
                    }
                }
                if (i % 500 <= 1)
                {
                    if (i % 2 == 0)
                    {
                        PeopleStore.Transaction.Commit();
                    }
                    else
                    {
                        PeopleStore.Flush();
                        AddressStore.Flush();
                        PeopleStore.Transaction.Rollback();
                    }
                    server.BeginTransaction();
                }
            }
            Console.WriteLine("Stress ended.");
        }