예제 #1
0
        public long BulkInsertTrialDataEmbedded(RavenConnection ravenConnection, IEnumerable<TrialData> trialBatch)
        {
            var watch = new Stopwatch();
            watch.Start();

            var eds = new EmbeddableDocumentStore { DataDirectory = @"C:\Projects\EDSTest\EDSData" };
            eds.Initialize();
            using (var bulkInsert = eds.BulkInsert())
            {
                foreach (var item in trialBatch)
                    bulkInsert.Store(item);
            }

            watch.Stop();
            return watch.ElapsedMilliseconds;
        }
예제 #2
0
        public static void ConfigureRaven(MvcApplication application)
        {
            var store = new EmbeddableDocumentStore
                                {
                                    DataDirectory = "~/App_Data/Database",
                                    UseEmbeddedHttpServer = true
                                };

            store.Initialize();
            MvcApplication.DocumentStore = store;

            IndexCreation.CreateIndexes(typeof(MvcApplication).Assembly, store);

            var statistics = store.DatabaseCommands.GetStatistics();

            if (statistics.CountOfDocuments < 5)
                using (var bulkInsert = store.BulkInsert())
                    LoadRestaurants(application.Server.MapPath("~/App_Data/Restaurants.csv"), bulkInsert);
        }
예제 #3
0
        public static void ConfigureRaven(MvcApplication application)
        {
            var store = new EmbeddableDocumentStore
                                {
                                    DataDirectory = "~/App_Data/Database",
                                    UseEmbeddedHttpServer = true
                                };

            store.Conventions.CustomizeJsonSerializer = x => x.Converters.Add(new GeoJsonConverter());
            store.Initialize();
            MvcApplication.DocumentStore = store;

            store.ExecuteIndex(new RestaurantIndex());
            store.ExecuteTransformer(new RestaurantsTransformer());

            var statistics = store.DatabaseCommands.GetStatistics();

            if (statistics.CountOfDocuments < 5)
                using (var bulkInsert = store.BulkInsert())
                    LoadRestaurants(application.Server.MapPath("~/App_Data/Restaurants.csv"), bulkInsert);
        }
예제 #4
0
        public void CanStoreDocumentWithNonStringIdPropertyAndDefaultValue()

        {
            using (var store = new EmbeddableDocumentStore
            {
                RunInMemory = true,
                Configuration =
                {
                    RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true
                }

            })

            {
                store.Configuration.Storage.Voron.AllowOn32Bits = true;
                store.Initialize();

                using (var insert = store.BulkInsert())
                {
                    Assert.DoesNotThrow(() => insert.Store(new ExampleInt32()));
                    Assert.DoesNotThrow(() => insert.Store(new ExampleInt64()));
                }
            }
        }
예제 #5
0
        public static void Update()
        {
            using (Siaqodb siaqodb = new Siaqodb())
            {
                siaqodb.Open(siaqodbPath, 300 * OneMB, 200);

                Console.WriteLine("Siaqodb UPDATE...");
                var stopwatch = new Stopwatch();
                stopwatch.Start();
                var trans = siaqodb.BeginTransaction();
                for (int i = 0; i < ENTITY_COUNT; i++)
                {
                    Document doc = new Document();
                    doc.Key = entities[i].Id;
                    entities[i].StringValue += i.ToString();
                    entities[i].IntValue++;
                    //set document content
                    doc.SetContent<MyEntity>(entities[i]);
                   //update the index too
                    doc.SetTag("myint", entities[i].IntValue);

                    //store the doc within the Bucket called 'myentities'
                    siaqodb.Documents["myentities"].Store(doc, trans);
                }
                trans.Commit();

                stopwatch.Stop();
                Console.WriteLine("Siaqodb UPDATE took:" + stopwatch.Elapsed);

            }
            using (EmbeddableDocumentStore store = new EmbeddableDocumentStore
            {
                DataDirectory = ravenDBPath

            })
            {
                store.Configuration.DefaultStorageTypeName = "voron";
                store.Initialize(); // initializes document store, by connecting to server and downloading various configurations
                Raven.Abstractions.Data.BulkInsertOptions opt = new Raven.Abstractions.Data.BulkInsertOptions()
                { OverwriteExisting = true };
                using (BulkInsertOperation bulkInsert = store.BulkInsert(null,opt ))
                {
                    Console.WriteLine("RavenDB UPDATE...");
                    var stopwatch = new Stopwatch();
                    stopwatch.Start();

                    for (int i = 0; i < ENTITY_COUNT; i++)
                    {
                        entities[i].StringValue += i.ToString();
                        entities[i].IntValue++;
                        bulkInsert.Store(entities[i], entities[i].Id);
                    }

                    stopwatch.Stop();
                    Console.WriteLine("RavenDB UPDATE took:" + stopwatch.Elapsed);

                }
            }
        }
예제 #6
0
        public static void Insert()
        {
            GenerateEntities();

            using (Siaqodb siaqodb = new Siaqodb())
            {
                siaqodb.Open(siaqodbPath, 300 * OneMB, 200);

                Console.WriteLine("Siaqodb INSERT...");
                var stopwatch = new Stopwatch();
                stopwatch.Start();
                var trans = siaqodb.BeginTransaction();
                for (int i = 0; i < ENTITY_COUNT; i++)
                {
                    Document doc = new Document();
                    doc.Key = entities[i].Id;
                    //set document content
                    doc.SetContent<MyEntity>(entities[i]);
                    //set tags(indexes)
                    doc.SetTag("myint", entities[i].IntValue);

                    //store the doc within the Bucket called 'myentities'
                    siaqodb.Documents["myentities"].Store(doc, trans);
                }
                trans.Commit();
                stopwatch.Stop();
                Console.WriteLine("Siaqodb INSERT took:" + stopwatch.Elapsed);

            }
            using (EmbeddableDocumentStore store = new EmbeddableDocumentStore
            {
                DataDirectory = ravenDBPath

            })
            {
                store.Configuration.DefaultStorageTypeName = "voron";
                store.Initialize(); // initializes document store, by connecting to server and downloading various configurations

                store.DatabaseCommands.PutIndex("MyEntity/IntValue",
                      new IndexDefinitionBuilder<MyEntity>()
                      {
                          Map = myints => from mi in myints
                                          select new { IntValue = mi.IntValue }
                      }, true);

                using (BulkInsertOperation bulkInsert = store.BulkInsert())
                {
                    Console.WriteLine("RavenDB INSERT...");
                    var stopwatch = new Stopwatch();
                    stopwatch.Start();

                    for (int i = 0; i < ENTITY_COUNT; i++)
                    {
                        bulkInsert.Store(entities[i], entities[i].Id);

                    }

                    stopwatch.Stop();
                    Console.WriteLine("RavenDB INSERT took:" + stopwatch.Elapsed);

                }
                using (IDocumentSession session = store.OpenSession()) // opens a session that will work in context of 'DefaultDatabase'
                {
                    //waiting for index to finish write operations
                    int temp = entities[0].IntValue;
                    var qq = (from myentity in session.Query<MyEntity>("MyEntity/IntValue").Customize(a => a.WaitForNonStaleResults())
                              where myentity.IntValue == temp
                              select myentity).ToList();
                }

            }
        }
예제 #7
0
        static void Main(string[] args)
        {
            Metrics.EnableConsoleReporting(10, TimeUnit.Seconds);
            var dataDir = GetDbPath();
            //Directory.Delete(dataDir);

            // Initialize RavenDB
            using (
                var documentStore = new EmbeddableDocumentStore
                                    {
                                        DataDirectory = dataDir,
                                        UseEmbeddedHttpServer = true,
                                        EnlistInDistributedTransactions = false
                                    })
            {

                documentStore.Configuration.Port = 33333;
                documentStore.Configuration.HostName = "localhost";
                documentStore.Configuration.CompiledIndexCacheDirectory = dataDir;
                documentStore.Configuration.VirtualDirectory = "/storage";

                documentStore.Conventions.SaveEnumsAsIntegers = true;

                documentStore.Initialize();

                new MessagesViewIndex().Execute(documentStore);
                documentStore.DatabaseCommands.PutIndex("Raven/DocumentsByEntityName", new IndexDefinition
                {
                    Map =
                        @"from doc in docs
            let Tag = doc[""@metadata""][""Raven-Entity-Name""]
            select new { Tag, LastModified = (DateTime)doc[""@metadata""][""Last-Modified""] };",
                    Indexes =
                    {
                        {"Tag", FieldIndexing.NotAnalyzed},
                        {"LastModified", FieldIndexing.NotAnalyzed},
                    },
                    Stores =
                    {
                        {"Tag", FieldStorage.No},
                        {"LastModified", FieldStorage.No}
                    },
                    TermVectors =
                    {
                        {"Tag", FieldTermVector.No},
                        {"LastModified", FieldTermVector.No}
                    },
                    DisableInMemoryIndexing = true,
                });

                const int documentsPerThread = 50000;
                const bool doBulk = true;
                const int bulkSize = 100;
                Console.WriteLine("Pushing documents...");
                if (doBulk)
                {
                    Console.WriteLine("(using bulk size of {0})", bulkSize);
                }

                var stopwatch = new Stopwatch();
                stopwatch.Start();

                Parallel.For(0, 10, l =>
                                    {
                                        using (var session = documentStore.BulkInsert())
                                        {
                                        for (int i = 0; i < documentsPerThread; i++)
                                              {
                                                      var msgGuid = Guid.NewGuid().ToString();
                                                      var msg = new ProcessedMessage
                                                            {
                                                                Id = "ProcessedMessage/" + msgGuid,
                                                                MessageMetadata = new Dictionary<string, object>
                                                                {
                                                                    {"MessageId", Guid.NewGuid().ToString()},
                                                                    {"MessageIntent", "1"},
                                                                    {"HeadersForSearching", "967cfa52-d114-4958-940a-a2d100053f8f 967cfa52-d114-4958-940a-a2d100053f8f MyClient USER-PC Send 4.3.4 2014-02-12 22:19:06:505614 Z 102ade9ea86c452da6394e4ba7e2900c text/xml MyMessages.RequestDataMessage, MyMessages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null 967cfa52-d114-4958-940a-a2d100053f8f\\0  316b2439-21b4-4b45-8989-a2d100053f8f MyServer USER-PC 2014-02-12 22:19:06:509614 Z 2014-02-12 22:19:06:510615 Z MyClient@USER-PC" + Guid.NewGuid()},
                                                                    {"TimeSent", DateTime.UtcNow},
                                                                    {"CriticalTime", TimeSpan.FromMinutes(1)},
                                                                    {"ProcessingTime", TimeSpan.FromMinutes(2)},
                                                                    {"DeliveryTime", TimeSpan.FromSeconds(2)},
                                                                    {"ContentLength", 213},
                                                                    {"ContentType", "text/xml"},
                                                                    {"SearchableBody", "<?xml version=\"1.0\" ?>\r\n<Messages xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"http://tempuri.net/MyMessages\">\n<RequestDataMessage>\n<DataId>102ade9e-a86c-452d-a639-4e4ba7e2900c</DataId>\n<String>&lt;node&gt;it&apos;s my &quot;node&quot; &amp; i like it&lt;node&gt;</String>\n</RequestDataMessage>\n</Messages>\r\n"},
                                                                    {"BodyUrl", "/messages/6d004d6f-56c2-fe71-15d1-27199b59484b/body"},
                                                                    {"BodySize", 369},
                                                                    {"IsSystemMessage", false},
                                                                    {"MessageType", "MyMessages.RequestDataMessage"},
                                                                    {"SearchableMessageType", "MyMessages RequestDataMessage"},
                                                                    {"SendingEndpoint", new EndpointDetails {Name = "MyClient", Machine = "USER-PC"}},
                                                                    {"ReceivingEndpoint", new EndpointDetails {Name = "MyClient", Machine = "USER-PC"}},
                                                                    {"ConversationId", Guid.NewGuid().ToString()},
                                                                },
                                                                Headers = new Dictionary<string, string>
                                                                {
                                                                    {"NServiceBus.MessageId", msgGuid},
                                                                    {"NServiceBus.CorrelationId", msgGuid},
                                                                    {"NServiceBus.OriginatingEndpoint", "MyClient"},
                                                                    {"NServiceBus.OriginatingMachine", "USER-PC"},
                                                                    {"NServiceBus.MessageIntent", "Send"},
                                                                    {"NServiceBus.Version", "4.3.4"},
                                                                    {"NServiceBus.TimeSent", DateTime.UtcNow.ToString()},
                                                                },
                                                                ProcessedAt = DateTime.UtcNow,
                                                                UniqueMessageId = msgGuid,
                                                            };
                                                      session.Store(msg);
                                                      indexedMeter.Mark();

                                                    }}
                                          });

                Console.WriteLine("Finished pushing documents, waiting for indexing to complete...");
                stopwatch.Stop();
                var elapsed = stopwatch.Elapsed;
                Console.WriteLine("Time to push {0} docs: {1} ({2} docs per sec on avg)", documentsPerThread * 10, elapsed, (documentsPerThread * 10) / (stopwatch.ElapsedMilliseconds / 1000));
                stopwatch = new Stopwatch();
                stopwatch.Start();

                var stats = documentStore.DatabaseCommands.GetStatistics();
                while (stats.StaleIndexes.Length > 0)
                {
                    Console.WriteLine("{0} Stale indexes: {1}", DateTime.UtcNow, stats.StaleIndexes.Length);
                    Console.WriteLine("{0} CurrentNumberOfItemsToIndexInSingleBatch: {1}", DateTime.UtcNow, stats.CurrentNumberOfItemsToIndexInSingleBatch);
                    Thread.Sleep(1000);
                    stats = documentStore.DatabaseCommands.GetStatistics();
                }
                stopwatch.Stop();

                Console.WriteLine("Indexing complete - waited {0} after the initial documents push (total of {1})", stopwatch.Elapsed, elapsed + stopwatch.Elapsed);
                Console.ReadKey();
            }
        }