性能提高及事务进程死锁问题

总结.,在硬件资源可以满足情况的情况下,提高性能 两个途径,或结合使用

1.多线程

2.缓存

3多进程

 

更新(最近的心得2011.9.6)

1.将类定义为静态,静态的字段可在静态构造函数中初始化,而它在整个应用程序中只执行一次,以后每次有新的访问者时都不需要重新实例化
2.使用数据库提供器工厂,以实现通用的数据访问代码。实现了不同的数据库数据操作的通用性,使代码更具有具有可扩展性、兼容性
3.构造一个静态配置类,缓存常用的需要从web.config中读取的,如将连接字符串从类的静态构造函数中读取出来,使得web.config文件不会在每次数据库操作时都被读取一次,而仅在类被初始化时读取该文件。
4.少于16字节的数据,用结构(值类型,不是存储在栈中)进行处理的的效率要高于类。
5.使用链接工厂

 

在提高工作效率的情况下,遇到了下面的问题:

System.Data.SqlClient.SqlException: 事务(进程 ID  58)与另一个进程已被死锁在  lock 资源上,且该事务已被选作死锁牺牲品。请重新运行该事务。
   在 System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
   在 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   在 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
   在 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   在 System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
   在 System.Data.SqlClient.SqlDataReader.get_MetaData()
   在 System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
   在 System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
   在 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
   在 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   在 System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   在 System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
   在 System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
   在 System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   在 System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   在 System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
   在 InformationCollection.DataAccess.SqlHelper.ExecuteDataset(SqlConnection connection, CommandType commandType, String commandText, SqlParameter[] commandParameters) 位置 D:\My Documents\Programing\项目\InformationCollection\InformationCollection\DataAccess\SQLHelper.cs:行号 612
   在 InformationCollection.DataAccess.SqlHelper.ExecuteDataset(SqlConnection connection, CommandType commandType, String commandText) 位置 D:\My Documents\Programing\项目\InformationCollection\InformationCollection\DataAccess\SQLHelper.cs:行号 581
   在 InformationCollection.DataAccess.DateUrlDal.GetMuchData() 位置 D:\My Documents\Programing\项目\InformationCollection\InformationCollection\DataAccess\DateUrlDal.cs:行号 71
   在 InformationCollection.Form1.StartMainThread() 位置 D:\My Documents\Programing\项目\InformationCollection\InformationCollection\Form1.cs:行号 97

 

原因:有时候并不一定真正的死锁,此处错误的原因,是因为一进程一直占有数据库资源,其它进程得不到资源一直处于饥饿状态造成的。

解决,以下两个方法都可行,已经验证过:1在内存中开辟一块数据域作为缓存,挖掘CPU潜能

2。针对错误,找到根源,此处解决是给数据表加索引,使进程只能锁定数据表中的一行,而不是整个表

 


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值