我正在检查MySQL的慢查询日志,并找到了如下条目:
# Time: 131108 4:16:34
# Query_time: 14.726425 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 1
SET timestamp=1383884194;
UPDATE `Artist` SET ImageFilename = NULL, Title = 'Elton John', PopularityRating = 657, UniqueID = NULL, Description = NULL, IsFeatured = 0, FeaturedText = '', MetaDescription = '', MetaTitle = NULL, _Temporary_LastUpdOn = '2013-11-08 04:15:58 ', _Temporary_Flag = 0, _Deleted = 0, _DeletedOn = NULL, Priority = 0 WHERE ID = 3449748;
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,执行此查询需要花费14.72秒的惊人时间,因为它只是一个WHERE主键的简单更新.我已经尝试重新执行查询,但现在它在0.095秒内执行,这更合理.
任何想法我如何调试为什么在那个特定的时间花了这么长时间?
编辑1:query_cache%变量
mysql> SHOW variables where variable_name like 'query_cache%'; …Run Code Online (Sandbox Code Playgroud) 想象一下,我有以下内容:
public interface IocInterface1 { }
public interface IocInterface2 { }
public class IocImpl : IocInterface1, IocInterface2 { }
Run Code Online (Sandbox Code Playgroud)
我想如果我尝试通过IoC获取上述类/接口的任何实例,我得到完全相同的实例,而不是每个类型一个单例.例如,b1与b2以下应该是真实的:
_container.RegisterSingle<IocInterface1, IocImpl>();
_container.RegisterSingle<IocInterface2, IocImpl>();
_container.RegisterSingle<IocImpl, IocImpl>();
var test1 = _container.GetInstance<IocInterface1>();
var test2 = _container.GetInstance<IocInterface2>();
var test3 = _container.GetInstance<IocImpl>();
bool b1 = test1 == test2;
bool b2 = test2 == test3;
Run Code Online (Sandbox Code Playgroud)
这可能吗?
c# dependency-injection ioc-container inversion-of-control simple-injector
关于如何设计适合单元测试的应用程序,我遇到了一个问题.
我正在尝试实施SRP(单一责任原则),据我所知,这涉及在单独的专用类中拆分大多数功能以保持代码更有条理.例如,我有这个特定的场景.
一个类RecurringProfile,它有一个方法.ActivateProfile().此方法的作用是将状态标记为已激活,并为下一个截止日期创建下一个(第一个)定期付款.例如,我打算拆分功能,以便在单独的类中创建下一个定期付款RecurringProfileNextPaymentCreator.我的想法是让这个类'RecurringProfile'在它的构造函数中作为参数:
RecurringProfileNextPaymentCreator(IRecurringProfile profile)
Run Code Online (Sandbox Code Playgroud)
但是,我认为这对于单元测试来说会有问题.我想创建一个测试ActivateProfile功能的单元测试.此方法将获取IRecurringProfileNextPaymentCreatorvia依赖注入(Ninject)的实例,并调用该方法.CreateNextPayment.
我创建一个单元测试的想法是创建一个模拟IRecurringProfileNextPaymentCreator和替换,以便我可以验证.ActivateProfile()实际调用的方法.但是,由于构造函数参数,这不适合作为NInject的默认构造函数.必须为这种情况创建一个自定义的NInject提供程序(我可以在整个解决方案中拥有许多这样的类)将有点矫枉过正.
任何想法/最佳实践如何进行此操作?
- 下面是关于上述示例的示例代码:(请注意,代码是手写的,在语法上不是100%正确)
public class RecurringProfile
{
public void ActivateProfile()
{
this.Status = Enums.ProfileStatus.Activated;
//now it should create the first recurring payment
IRecurringProfileNextPaymentCreator creator = NInject.Get<IRecurringProfileNextPaymentCreator>();
creator.CreateNextPayment(this); //this is what I'm having an issue about
}
}
Run Code Online (Sandbox Code Playgroud)
一个样本单元测试:
public void TestActivateProfile()
{
var mockPaymentCreator = new Mock<IRecurringProfileNextPaymentCreator>();
NInject.Bind<IRecurringProfileNextPaymentCreator>(mockPaymentCreator.Object);
RecurringProfile profile = new RecurringProfile();
profile.ActivateProfile();
Assert.That(profile.Status …Run Code Online (Sandbox Code Playgroud) 我一直在尝试安装'调试工具',以便尝试分析转储文件服务器崩溃(Windows Server 2008 R2).
我过去常常这样做,但我找不到如何安装/找到Windows 7的调试工具.
我已经阅读了这篇知识库文章:http://support.microsoft.com/kb/315263.
然后,我尝试从以下文章(http://msdn.microsoft.com/en-us/windows/hardware/gg463009.aspx)下载"Windows调试工具" .我选择"将Windows调试工具安装为独立组件",下载文件并进行安装.
它安装成功,但我仍然找不到文件.这对我来说似乎是一个愚蠢的问题,但我无法以任何方式找到调试工具!我甚至试图下载上面提到的Windows 7调试工具(http://www.microsoft.com/en-us/download/details.aspx?id=8279),但再次无法找到它们!
任何帮助将非常感激
我试图模拟一个接口,它接受一个DateTimeOffset?参数.突然之间,Visual Studio开始报告"内部编译器错误"并且它已"停止工作".经过大量的试验,我开始逐个删除文件,然后逐行编码.这减少到下面的代码,它重现了这个错误:
public class testClass
{
public interface ITest
{
void Test(DateTimeOffset? date);
}
public void test2()
{
var mock = new Mock<ITest>();
mock.Setup(x => x.Test(new DateTime(2012, 1, 1)));
}
}
Run Code Online (Sandbox Code Playgroud)
问题似乎是这样的:
mock.Setup(x => x.Test(new DateTime(2012, 1, 1)));
Run Code Online (Sandbox Code Playgroud)
如果我评论它,编译器工作正常.此外,问题是我正在设置一个new DateTime()适合的DateTimeOffset.
这是一个错误Moq,还是VS2012?以前有人遇到过这个错误吗?
以下代码示例也导致编译错误,包括常规Visual Studio 2012编译器和2012年9月Roslyn CTP:
using System;
using System.Linq.Expressions;
public interface ITest
{
void Test(DateTimeOffset? date);
}
public class TestClass
{
Expression<Action<ITest>> t = x => x.Test(new DateTime(2012, 1, …Run Code Online (Sandbox Code Playgroud) 我在分布式系统中有两个组件,它们发送使用 Newtonsoft.JSON (JSON.Net) 序列化/反序列化的消息。
消息属性当前以挪威语发送,我希望将代码库翻译成英语。由于发生了一些变化,一些消息将以挪威语发送,并由已升级到英语版本的组件处理,因此它需要能够支持这两种语言。
我希望在反序列化时,“挪威”属性名称和英语都将映射到同一属性。例如:
例如,采用英语中的“name”或挪威语中的“navn”。
public class Message
{
[JsonProperty("Navn")]
public string Name { get; set;}
}
Run Code Online (Sandbox Code Playgroud)
上面的问题是它只能从Navn => Name. 我希望它能够将Navn和映射Name到Name.
这在 Newtonsoft.JSON 中可用,无需太多自定义编码吗?
我想知道是否有任何方法可以使用分布式服务器(如 MySQL Cluster)对部署在多台服务器上的 asp.net Web 应用程序执行“锁定”。
例如,以更新帐户余额的经典示例为例。不应有两个请求同时更新相同的帐户余额。例如:
会员 1 账户余额为 100。
因此请求 A 将余额从 100 更新为 200 并保存。
请求 B 将余额更新为 150,并保存。
这些都完全同时发生,因此丢失了信息,因为最终结果应该是 250。
一个锁定如何才能使请求 B 必须等到请求 A 完成,直到它取回余额。如果它是单个进程,这可以通过应用程序范围的锁来实现。但是,由于有多个独立的进程,这对服务器 1 不起作用,它没有被锁定,服务器 2 也没有
任何想法或最佳实践如何做到这一点?
我在检查NHibernate的日志文件时,发现了一些随机错误,如下:
NHibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [MaltaIndependent.Modules._AutoGen.MemberImpl#353796206]
at NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object id, Object[] fields, Object[] oldFields, Object rowId, Boolean[] includeProperty, Int32 j, Object oldVersion, Object obj, SqlCommandInfo sql, ISessionImplementor session) in c:\Repository\Work\CodeBase\C#\+OpenSource\nHibernate\nhibernate-core-master-v3.3.1\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs:line 2821
at NHibernate.Persister.Entity.AbstractEntityPersister.UpdateOrInsert(Object id, Object[] fields, Object[] oldFields, Object rowId, Boolean[] includeProperty, Int32 j, Object oldVersion, Object obj, SqlCommandInfo sql, ISessionImplementor session) in c:\Repository\Work\CodeBase\C#\+OpenSource\nHibernate\nhibernate-core-master-v3.3.1\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs:line 2702
at NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object id, Object[] fields, Int32[] dirtyFields, Boolean hasDirtyCollection, Object[] oldFields, Object oldVersion, Object obj, Object …Run Code Online (Sandbox Code Playgroud) 是否可以知道特定模板是否已使用 RazorEngine 编译?基本上,如果你打电话:
Razor.Parse("Hello there @Model.Name", model, "hello-world");
Run Code Online (Sandbox Code Playgroud)
这将使用键“hello-world”编译模板。第一次这可能需要几毫秒,但由于缓存,第二次几乎是即时的。是否可以知道模板是否已经编译?就像是:
var isCompiled = Razor.IsCompiled("Hello there @Model.Name", "hello-world");
Run Code Online (Sandbox Code Playgroud) c# ×7
asp.net ×2
concurrency ×1
crash ×1
crash-dumps ×1
encoding ×1
jpeg ×1
json ×1
json.net ×1
locking ×1
minidump ×1
mysql ×1
nhibernate ×1
ninject ×1
performance ×1
razor ×1
razor-2 ×1
roslyn ×1
unit-testing ×1
windows ×1