An OLTP scenario is characterized by a large number of concurrent operations that create, update, and delete data, packaged up as transactions. Most modern RDBMSs implement locking and logging strategies to ensure that the ACID (Atomicity, Consistency, Isolation, and Durability) properties of transactions are maintained. These features aim to guarantee the integrity of the data, but they necessarily have an impact on the performance of your transactions, and you should try and minimize their negative effects wherever possible. The following list provides some suggestions:

  • Keep transactions short. A long-running transaction can lock data for an extended period of time, increasing the chances that it will block operations being performed by other concurrent transactions. Therefore, to maximize throughput, it is important to design the business logic carefully, and only perform the operations that are absolutely necessary within the bounds of a transaction.
  • Avoid repeating the same work. Poorly designed transactions can lead to deadlock, resulting in operations being undone. Your applications have to detect this situation and may need to repeat the transaction, reducing the performance of the system still further. Design your transactions to minimize this possibility. For example, always access tables and other resources in the same sequence in all operations to avoid the “deadly embrace” form of deadlock.
  • Avoid implementing database triggers over data that is updated frequently. Many RDBMSs support triggers that run automatically when specified data is inserted, updated, or deleted. These triggers run as part of the same transaction that fired them, and they add complexity to the transaction. The developer writing the application code to implement the transaction might not be aware that the triggers exist, and might attempt to duplicate their work, possibly resulting in deadlock.
  • Do not include interactivity or other actions that might take an indeterminate period of time. If your transactions depend upon input from a user, or data retrieved from a remote source, then gather this data before initiating the transaction. Users may take a long time to provide data, and information received from a remote source may take a long time to arrive (especially if the remote data source is some distant site being accessed across the Internet), give rise to the same consequences as a long-running transaction.
  • Implement transactions locally in the database. Many RDBMSs support the concept of stored procedures or other code that is controlled and run by the database management system. You can define the operations that implement a transaction by using a stored procedure, and then simply invoke this stored procedure from your application code. Most RDBMSs are more easily able to refactor and optimize the operations in a stored procedure than they are the individual statements for a transaction implemented by application code that runs outside of the database.
    This approach reduces the dependency that the application has on a particular database schema but it might introduce a dependency on the database technology. If you switch to a different type of database, you might need to completely reimplement this aspect of your system.

最新文章

  1. Protocol Buffer搭建及示例
  2. kubernetes多节点部署解析
  3. KendoUI系列:AutoComplete
  4. JS 删除字符串最后一个字符的几种方法
  5. ireport启动闪退问题
  6. Android_Intent_startActivityForResult
  7. PHPstrom2016.1激活与汉化【2016.06.21依旧可用】
  8. bzoj1306
  9. K - Leapin' Lizards - HDU 2732(最大流)
  10. 找工作笔试面试那些事儿(10)---SQL语句总结
  11. 国产与第三方库FFmpeg SDK
  12. hdu_5690_All X(找循环节)
  13. macbook pro 突破校园网inode客户端限制分享网络
  14. python 数据驱动(ddt)
  15. [bzoj4908][BeiJing2017]开车
  16. Gradle 1.12用户指南翻译——第二十八章. Jetty 插件
  17. 《React Native 精解与实战》书籍连载「Node.js 简介与 React Native 开发环境配置」
  18. 十三、u-boot 调试-- NOR FLASH 支持
  19. Mybatis自动生成,针对字段类型为text等会默认产生XXXXWithBlobs的方法问题
  20. Uncommon Words from Two Sentences LT884

热门文章

  1. Linux 生产实习01
  2. FreeMarker使用小记(HelloWorld)
  3. .NetCore中的程序通过Docker在CentOS中部署
  4. svn导入项目和部署方面的相关问题
  5. Shell 利用 curl 模拟登陆
  6. wfst的compose算法
  7. CPU的主频
  8. 表达式树(Expression Tree)
  9. 利用Microsoft Sql Server Management studio 创建数据库的示例
  10. flask run方法和run_simple