Git Product home page Git Product logo

write_skew_demo's Introduction

README

About

Do you think you understand concurrency in databases? Well, use this project to test your understanding.

This example illustrates the write skew problem using the 4 canonical examples on Postgres wiki. We run the example under 3 isolation modes:

  • READ COMMITTED
  • REPEATABLE READ implemented using Snapshot Isolation or MVCC in Postgres
  • SERIALIZABLE implemented using Serializable Snapshot Isolation in Postgres The Snapshot Isolation mode (i.e., READ REPEATABLE) cannot hanlde write skew. You have to either use a higher isolation level or resort to explicit locking in your code. Besides illustrating concurrency you can use this project to learn how to use Sequelize.

Build

npm i
npm run build

Run

First, edit run-pg.sh and run-mysql.sh as necessary.

To run the 4 examples one by one:

Postgres:

npm run pg-black-white-demo
npm run pg-intersecting-data-demo
npm run pg-overdraft-protection-demo
npm run pg-rgb-demo

MySQL:

npm run mysql-black-white-demo
npm run mysql-intersecting-data-demo
npm run mysql-overdraft-protection-demo
npm run mysql-rgb-demo

Full log of successful runs can be found under the logs folder.

Observations

Both MySQL and Postgres are able to handle write skew at the SERIALIZABLE level but the way its implemented is different between the two. MySQL uses a combination of MVCC and 2-phase locking (2PL) whereas Postgres uses Serializable Snapshot Isolation (SSI) which does not cause any locking. They give the same result for the overdraft protection and intersecting data examples. One of the transactions is aborted whereas the other is allowed to commit. However it is interesting to note that for the black-white example, MySQL serializes and commits both transactions whereas Postgres aborts one of the transactions. And again, for the rgb example MySQL serializes the 3 transactions and commits them one by one whereas Postgres aborts 2 transactions and only allows one to commit. Which one do you like? The elephant or the dolphin? Let me know.

write_skew_demo's People

Contributors

siddhsql avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.