I have an Asp.net MVC application running on AppHarbor. It has the everyday email ordering process:
我有一个在AppHarbor上运行的Asp.net MVC应用程序。它有日常的电子邮件订购流程:
- User enters their email and submits it.
- 用户输入他们的电子邮件并提交它。
- System processes order and sends out email with a link.
- 系统处理订单并通过链接发送电子邮件。
- User checks email and clicks the link to do the next step...
- 用户检查电子邮件并点击链接来完成下一步……
The thing is that between steps #2 and #3 a lot of time can pass. Some users check their emails immediately, others after a day or even later. The main thing is that enough time can pass that the application on the server ends.
问题是,在步骤2和步骤3之间,很多时间都可以过去。一些用户会立即查看他们的电子邮件,另一些用户会在一天后甚至更晚的时候查看邮件。最重要的是,足够的时间可以传递给服务器上的应用程序。
So when the user clicks a link it may mean that they will have to wait for a bit for the application to start back up...
因此,当用户点击一个链接时,可能意味着他们将不得不等待一段时间,等待应用程序重新启动……
Question
When step #3 processes a record in database is updated with a timestamp (type is datetime
of course) when step #3 took place. But grok this: I can see records with completely identical timestamps! How can that even happen?
当步骤#3处理数据库中的记录时,当步骤#3发生时,将使用时间戳(类型当然是datetime)更新数据库中的记录。但是我可以看到完全相同时间戳的记录!这怎么可能发生呢?
Timestamp gets generated in application layer and then pushes the updated to database. I'm using PetaPoco for data access.
在应用层中生成时间戳,然后将更新的内容推送到数据库。我用PetaPoco来访问数据。
What can cause multiple records to record the same time? My application has such small traffic that it actually does shut down sometimes during day so I find it hard to believe that multiple (up to three) users did step #3 at exactly the same time. And since this is running on a single process I suppose it's impossible...
什么会导致多个记录同时记录?我的应用程序的流量如此之小,以至于有时会在白天关闭,因此我很难相信多个(最多三个)用户同时执行了第3步。因为这是在一个单一的过程中运行我认为这是不可能的…
What can be the cause for this?
为什么会这样呢?
Update code is really really simple
更新代码真的很简单
using (var db = this.DataContext)
{
db.Execute(Sql
.Builder
.Append("update dbo.SteppedProcess set Step3ProcessedOn = @0", DateTime.Now)
.Where("Step3ProcessedOn is null")
.Where("Id = @0", id));
}
1 个解决方案
#1
1
ASP.NET is running multiple threads, even on a single CPU. So this could happen. I guess it is more like to happen in your case because after the app has shut down, it needs to start up. All request coming in during the startup phase are queued and executed immediately and simultaneously once your app becomes available. This opens up a bigger window of opportunity.
ASP。NET运行多个线程,甚至在一个CPU上。这可能发生。我猜这更像是发生在你的案例中,因为在应用程序关闭后,它需要启动。在启动阶段进入的所有请求都被排队并在应用程序可用时立即同时执行。这打开了一个更大的机会之窗。
And because the Windows clock has about 15ms resolution, there is a big chance that simultaneous request will get the same timestamp.
而且由于Windows时钟有大约15ms的分辨率,所以同时请求将获得相同的时间戳是很有可能的。
#1
1
ASP.NET is running multiple threads, even on a single CPU. So this could happen. I guess it is more like to happen in your case because after the app has shut down, it needs to start up. All request coming in during the startup phase are queued and executed immediately and simultaneously once your app becomes available. This opens up a bigger window of opportunity.
ASP。NET运行多个线程,甚至在一个CPU上。这可能发生。我猜这更像是发生在你的案例中,因为在应用程序关闭后,它需要启动。在启动阶段进入的所有请求都被排队并在应用程序可用时立即同时执行。这打开了一个更大的机会之窗。
And because the Windows clock has about 15ms resolution, there is a big chance that simultaneous request will get the same timestamp.
而且由于Windows时钟有大约15ms的分辨率,所以同时请求将获得相同的时间戳是很有可能的。