我正在为我未来的项目测试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) 我看到了Eloquera db并对它印象深刻.目前我正在考虑在Eloquera而不是Sql Server上开发我的下一个项目.所以我有几个问题.
database relational-database object-oriented-database eloquera
我对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) 我有几亿行的数据库.我正在运行以下查询:
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) 假设我有两个控制器:ControllerA和ControllerB.这两个控制器都接受参数IFooInterface.现在我有2个IFooInterface,FooA和FooB的实现.我想在ControllerA中注入FooA,在ControllerB中注入FooB.这很容易在Ninject中实现,但由于性能更好,我正在转向Simple Injector.那么我怎样才能在Simple Injector中做到这一点?请注意,ControllerA和ControllerB驻留在不同的程序集中并动态加载.
谢谢
我认为问题很清楚.PLinq不允许您创建超过63个线程(WithDegreeOfParallelism不允许它,抛出ArgumentOutOfRangeException).在极少数情况下,我们需要从线程池中获取超过63个线程(例如I/O操作,其中任务需要比平时更多的时间来完成).据我所知,Parallel类也有相同的限制.有没有解决方法?这种限制的原因是什么?
以下代码让我有点困惑:
char * strcpy(char * p, const char * q) {
while (*p++=*q++);
//return
}
Run Code Online (Sandbox Code Playgroud)
这是功能的简化实现strcpy.从这段代码中,我们看到指针p并q递增然后解除引用并q分配给指针p直到\0达到char.
我想有人解释while循环的第一次迭代.
我想在我的项目中使用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)
但要指定元数据以选择要创建的类实例.
非常感谢您的帮助.
谢谢.
我有一个非常简单的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)
我如何实现这一目标?
我正在尝试为我的项目实现异步套接字.这是代码
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# ×6
.net ×4
asyncsocket ×1
c ×1
database ×1
eloquera ×1
mef ×1
nhibernate ×1
ninject ×1
ninject-2 ×1
performance ×1
plinq ×1
pointers ×1
postgresql ×1
ravendb ×1
serversocket ×1
sockets ×1