我有一个 sql server 数据库设置,它接受来自使用线程运行的 Visual Studio 应用程序的插入事务。现在事务陷入僵局,我有一个解决方法,当 Visual Studio 2010 代码检测到超时时,它只会重新尝试插入数据。查看我设置的文本日志,这种情况发生得太频繁并导致性能问题。一些在线资源表明找到了有问题的事务并将其杀死,但如果我的应用程序依赖于在数据库中获得的结果,那可能不是一个选项。有没有关于如何处理这个问题的建议。我在 Visual Studion 2010 中使用 Parallel Taskfactory,所以在任何给定时间至少有 1000 个线程在运行?
一些要查看的代码:我的插入代码
任何想法都非常感谢。
sql表架构
Table PostFeed
id int
entryid varchar(100)
feed varchar(MAX)
pubdate varchar(50)
authorName nvarchar(100)
authorId nvarchar(100)
age nvarchar(50)
locale nvarchar(50)
pic nvarchar(50)
searchterm nvarchar(100)
dateadded datetime
PK - entryid + searchterm
用于插入的存储过程,因此它执行大量插入并依赖主键约束进行重复检查
完成表创建
USE [Feeds]
GO
/****** Object: Table [dbo].[PostFeed] Script Date: 09/21/2011 11:21:38 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[PostFeed](
[id] [int] IDENTITY(1,1) NOT NULL,
[entryId] [varchar](100) NOT NULL,
[feed] [varchar](max) NULL,
[entryContent] [nvarchar](max) NULL,
[pubDate] [varchar](50) NOT NULL,
[authorName] [nvarchar](100) NOT NULL,
[authorId] [nvarchar](100) NULL,
[age] [nvarchar](50) NULL,
[sex] [nvarchar](50) NULL,
[locale] [nvarchar](50) NULL,
[pic] [nvarchar](100) NULL,
[fanPage] [nvarchar](400) NULL,
[faceTitle] [nvarchar](100) NULL,
[feedtype] [varchar](50) NULL,
[searchterm] [nvarchar](400) NOT NULL,
[clientId] [nvarchar](100) NULL,
[dateadded] [datetime] NULL,
[matchfound] [nvarchar](50) NULL,
[hashField] AS ([dbo].[getMd5Hash]([entryId])),
CONSTRAINT [PK_Feed] PRIMARY KEY CLUSTERED
(
[entryId] ASC,
[searchterm] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO SET ANSI_PADDING OFF
GO
我尝试导出死锁图,但无法让它工作,所以这里有几行来自跟踪
Lock:Timeout 60468 sa 0X01 247 G01 sa 2011-09- 21 16:00:44.750 1:4557807 3463314605 .Net SqlClient Data Provider 0 0XEF8B45000100000000000000070006 22164 7 postFeeds 0 2011-09-21 16:00:44.750 1 G02 0 - LOCK 8 - IX 0 72057594075152384 1 - TRANSACTION 0 6 - PAGE
Lock:Timeout 60469 sa 0X01 478 G01 sa 2011-09- 21 16:00:44.887 (7bf23fc490ce) 3463299315 .Net SqlClient Data Provider 0 0X3802000000017BF23FC490CE070007 17900 7 postFeeds 0 2011-09-21 16:00:44.887 1 G02 0 - LOCK 5 - X 0 72057594075152384 1 - TRANSACTION 0 7 - KEY
Lock:Timeout 60470 sa 0X01 803 G01 sa 2011-09- 21 16:00:44.887 (379349b72c77) 3463296982 .Net SqlClient Data Provider 0 0X380200000001379349B72C77070007 17900 7 postFeeds 0 2011-09-21 16:00:44.887 1 G02 0 - LOCK 5 - X 0 72057594075152384 1 - TRANSACTION 0 7 - KEY
Lock:Timeout 60471 tdbuser 0X048D73EF643661429B907E6106F78358 93 G01 tdbuser 2011-09-21 16:02:41.333 1:14386936 3463346220 .Net SqlClient Data Provider 0