【问题标题】:RavenDB export\import data to SQL ServerRavenDB 导出\导入数据到 SQL Server
【发布时间】:2012-05-28 21:49:22
【问题描述】:

简单问题:如何将数据从 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();
     }
}

【问题讨论】:

  • 发布您用于插入到 RavenDB 的代码。插入速度是代码的一个因素,可能是它运行的机器。

标签: sql-server ravendb


【解决方案1】:

我只是在做同样的事情。速度对我来说并不是真正关心的问题,所以我不知道这是否比你的快。

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();
    }
}

【讨论】:

  • 我正在做和你一样的事情,但是对于 1000 亿行,这需要很长时间。
【解决方案2】:

我相信它在标准服务器上支持每秒 1,000 次写入。

当我增加缓存大小时,性能会提高。 Raven/Esent/CacheSizeMax

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

【讨论】:

    猜你喜欢
    • 2011-03-13
    • 2012-05-27
    • 2011-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多