首页 文章

RavenDB导出\导入数据到SQL Server

提问于
浏览
1

简单问题:如何将数据从SQL Server导出到RavenDB?

我编写的脚本从SQL Server获取数据并在raven中存储,但它的工作速度非常慢 . 每秒约2500个插入 .

编辑:我的代码

for (int i = 0; i < count; i+=8196)
    {
        StoreInTaven(WordStats.Skip(i).Take(8196).Select(x => new KeyPhraseInfo(){
           Key = x.Word,
           Id = x.Id,
           Count = x.Count,
           Date = x.Date
        }));
        GC.Collect();
    }



public static void StoreInTaven(IEnumerable<KeyPhraseInfo> wordStats)
{
     using(var session = store.OpenSession())
     {
           foreach (var wordStat in wordStats)
           {
              session.Store(wordStat);
           }

           session.SaveChanges();
     }
}

2 回答

  • 0

    我只是在做同样的事情 . 速度对我来说并不是一个问题所以我不知道这是否比你的速度快 .

    public static void CopyFromSqlServerToRaven(IDocumentSession db, bool ravenDeleteAll=true)
    {
        if (ravenDeleteAll) db.DeleteAll();
    
        using (var connection = new SqlConnection(SqlConnectionString))
        {
            var command = new SqlCommand(SqlGetContentItems, connection);
            command.Connection.Open();
            using (var reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    db.Store(new ContentItem
                                {
                                        Id = reader["Id"].ToString(),
                                        Title = (string)reader["Name"],
                                        Description = (string)reader["ShortDescription"],
                                        Keywords = (string)reader["SearchKeywords"]
                                });
                }
            }
            db.SaveChanges();
        }
    }
    
  • 1

    我相信它在标准服务器上支持每秒1000次写入 .

    当我增加缓存大小时,性能会提高 . 乌鸦/ ESENT / CacheSizeMax

    http://ravendb.net/docs/server/administration/configuration

相关问题