小编Dav*_*ita的帖子

RavenDB选择性能差

我正在为我未来的项目测试RavenDB.数据库性能是我必须要求的,这就是为什么我希望能够将RavenDB调整到至少在SQL Server的性能范围内,但是我的测试显示raven db在选择查询中比SQL Server慢大约10x-20x,甚至当RavenDB被索引并且SQL Server没有任何索引时.

我用150k文件填充数据库.每个文档都有一个子元素集合.Db尺寸约为.1GB也是索引大小.Raven/Esent/CacheSizeMax设置为2048,Raven/Esent/MaxVerPages设置为128.以下是文档的外观:

{
  "Date": "2028-09-29T01:27:13.7981628",
  "Items": [
    {
      {
      "ProductId": "products/673",
      "Quantity": 26,
      "Price": {
        "Amount": 2443.0,
        "Currency": "USD"
      }
    },
    {
      "ProductId": "products/649",
      "Quantity": 10,
      "Price": {
        "Amount": 1642.0,
        "Currency": "USD"
      }
    }
  ],
  "CustomerId": "customers/10"
}


public class Order
{
    public DateTime Date { get; set; }
    public IList<OrderItem> Items { get; set; }
    public string CustomerId { get; set; }
}

public class OrderItem
{
    public string ProductId { get; set; }
    public …
Run Code Online (Sandbox Code Playgroud)

ravendb

8
推荐指数
1
解决办法
3374
查看次数

Eloquera对象数据库

我看到了Eloquera db并对它印象深刻.目前我正在考虑在Eloquera而不是Sql Server上开发我的下一个项目.所以我有几个问题.

  1. Eloquera在企业和重载中的表现如何?
  2. 它与其他开源和商业RDBMS(我的意思是性能)相比如何?
  3. 它在生产环境中是否足够稳定且安全?
  4. 它有像SQL Management Studio这样的GUI工具吗?
  5. 有人做过比较Eloquera和其他RDBMS的基准吗?

database relational-database object-oriented-database eloquera

7
推荐指数
1
解决办法
832
查看次数

NHibernate在删除之前更新了行?

我对nhibernate有一种奇怪的行为.问题是nhibernate在删除实体之前执行更新.我有一个Category类和一个Product类.类别有一袋产品.当我从Category中删除产品时,nhibernate会执行以下操作:

  • 它更新了我从集合中删除的产品实体
  • 它从数据库中删除产品实体.

这是映射

  <class name="Category"> 
    <id name="Id"> 
      <generator class="hilo" /> 
    </id> 
    <property name="Name" lazy="false" length="20" /> 

    <bag name="Products" cascade="all-delete-orphan" lazy="false" 
inverse="false"> 
      <key column="CategoryId" /> 
      <one-to-many class="Product" /> 
    </bag> 
  </class> 

  <class name="Product"> 
    <id name="Id"> 
      <generator class="hilo" /> 
    </id> 
    <property name="Name" lazy="false" /> 
    <property name="Discontinued" lazy="false" /> 
    <property name="Price" lazy="false" /> 
    <many-to-one name="Category" 
             class="Category" 
             column="CategoryId" 
             cascade="none" /> 
  </class>
Run Code Online (Sandbox Code Playgroud)

这是代码

    using (var session = NHibernateHelper.OpenSession()) 
    using (var transaction = session.BeginTransaction()) 
    { 
        var c1 = session.Load<Category>(32768); 
        c1.Ps.RemoveAt(0); 

        session.SaveOrUpdate(c1); 
        transaction.Commit(); 
    }
Run Code Online (Sandbox Code Playgroud)

这是结果:

exec sp_executesql …
Run Code Online (Sandbox Code Playgroud)

.net c# nhibernate

7
推荐指数
1
解决办法
3058
查看次数

PostgreSQL查询耗时太长

我有几亿行的数据库.我正在运行以下查询:

select * from "Payments" as p
inner join "PaymentOrders" as po
on po."Id" = p."PaymentOrderId"
inner join "Users" as u
On u."Id" = po."UserId"
INNER JOIN "Roles" as r
on u."RoleId" = r."Id"
Where r."Name" = 'Moses'
LIMIT 1000
Run Code Online (Sandbox Code Playgroud)

当where子句在数据库中找到匹配项时,我会在几毫秒内得到结果,但如果我修改查询并r."Name"在where子句中指定不存在,则需要花费太多时间才能完成.我猜PostgreSQL正在对Payments表(包含最多行)进行顺序扫描,逐行比较每一行.

是不是postgresql足够聪明,如果Roles表包含任何行,首先检查Name 'Moses'

角色表仅包含15行,而付款包含约3.5亿行.

我正在运行PostgreSQL 9.2.1.

顺便说一下,对同一模式/数据的相同查询在MS SQL Server上需要0.024ms才能完成.

我将在几个小时内更新问题并发布EXPLAIN ANALYZE数据.


这里解释分析结果:http://explain.depesz.com/s/7e7


这是服务器配置:

version PostgreSQL 9.2.1, compiled by Visual C++ build 1600, 64-bit
client_encoding UNICODE
effective_cache_size    4500MB
fsync   on
lc_collate …
Run Code Online (Sandbox Code Playgroud)

postgresql performance postgresql-performance

7
推荐指数
2
解决办法
1万
查看次数

简单的注射器条件注射

假设我有两个控制器:ControllerA和ControllerB.这两个控制器都接受参数IFooInterface.现在我有2个IFooInterface,FooA和FooB的实现.我想在ControllerA中注入FooA,在ControllerB中注入FooB.这很容易在Ninject中实现,但由于性能更好,我正在转向Simple Injector.那么我怎样才能在Simple Injector中做到这一点?请注意,ControllerA和ControllerB驻留在不同的程序集中并动态加载.

谢谢

.net c# dependency-injection simple-injector

7
推荐指数
2
解决办法
3649
查看次数

为什么PLinq不支持超过63个并行线程?

我认为问题很清楚.PLinq不允许您创建超过63个线程(WithDegreeOfParallelism不允许它,抛出ArgumentOutOfRangeException).在极少数情况下,我们需要从线程池中获取超过63个线程(例如I/O操作,其中任务需要比平时更多的时间来完成).据我所知,Parallel类也有相同的限制.有没有解决方法?这种限制的原因是什么?

.net c# multithreading plinq task-parallel-library

6
推荐指数
1
解决办法
432
查看次数

在while循环中后增量

以下代码让我有点困惑:

char * strcpy(char * p, const char * q) {
  while (*p++=*q++);
  //return
}
Run Code Online (Sandbox Code Playgroud)

这是功能的简化实现strcpy.从这段代码中,我们看到指针pq递增然后解除引用并q分配给指针p直到\0达到char.

我想有人解释while循环的第一次迭代.

c pointers post-increment

6
推荐指数
1
解决办法
2632
查看次数

带元数据的MEF GetExportedValue

我想在我的项目中使用MEF作为DI.我有一个项目,每个应该编写的类都驻留在那里(它们共享一个接口).现在我想通过指定元数据值来创建其中一个.这是定义:

public interface IGatewayResponseReader
{
    object Read(string msg);
}

[Export(typeof(IGatewayResponseReader))]
[ExportMetadata(G3Reader.META_KEY, "value1")]
public class TestReader1 : IGatewayResponseReader
{
    ...
}

[Export(typeof(IGatewayResponseReader))]
[ExportMetadata(G3Reader.META_KEY, "value2")]
public class TestReader2 : IGatewayResponseReader
{
    ...
}
Run Code Online (Sandbox Code Playgroud)

现在我想通过MEF创建一个TestReader1实例,但我不知道如何通过CompositionContainer按元数据进行过滤.我想要类似的东西

Container.GetExportedValue<IGatewayResponseReader>();
Run Code Online (Sandbox Code Playgroud)

但要指定元数据以选择要创建的类实例.

非常感谢您的帮助.

谢谢.

c# dependency-injection mef

5
推荐指数
1
解决办法
1964
查看次数

将参数传递给方法绑定

我有一个非常简单的Ninject绑定:

Bind<ISessionFactory>().ToMethod(x =>
    {
        return Fluently.Configure()
            .Database(SQLiteConfiguration.Standard
                .UsingFile(CreateOrGetDataFile("somefile.db")).AdoNetBatchSize(128))
            .Mappings( 
                m => m.FluentMappings.AddFromAssembly(Assembly.Load("Sauron.Core"))
                      .Conventions.Add(PrimaryKey.Name.Is(p => "Id"), ForeignKey.EndsWith("Id")))
            .BuildSessionFactory();
    }).InSingletonScope();
Run Code Online (Sandbox Code Playgroud)

我需要的是用参数替换"somefile.db".类似的东西

kernel.Get<ISessionFactory>("somefile.db");
Run Code Online (Sandbox Code Playgroud)

我如何实现这一目标?

.net c# dependency-injection ninject ninject-2

5
推荐指数
1
解决办法
1310
查看次数

Socket.Shutdown抛出SocketException

我正在尝试为我的项目实现异步套接字.这是代码

    public void Start(int listeningPort)
    {
        var ipHostInfo = Dns.Resolve(Dns.GetHostName());
        var ipAddress = ipHostInfo.AddressList[0];
        var localEndPoint = new IPEndPoint(ipAddress, listeningPort);

        _listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
        _listener.Bind(localEndPoint);
        _listener.Listen(3000);
        Started = true;

        Task.Factory.StartNew(() =>
        {
            while (Started)
            {
                allDone.Reset();

                _listener.BeginAccept(AcceptCallback, _listener);

                allDone.WaitOne();
            }
        });
    }

    public void Stop()
    {
        Started = false;
        _listener.Shutdown(SocketShutdown.Both); //<-- throws SocketException
        _listener.Close(2000);
        _listener = null;
    }

    public void Kick(IClient client)
    {
        try
        {
            Clients.Remove(client);
            client.Socket.Shutdown(SocketShutdown.Both);
            client.Socket.Close();
        }
        catch (Exception ex)
        {
            Debug.WriteLine(ex.Message);
        }
    }

    private void …
Run Code Online (Sandbox Code Playgroud)

c# sockets serversocket asyncsocket

5
推荐指数
1
解决办法
2704
查看次数