Giter VIP home page Giter VIP logo

em-mysql2's Introduction

What is this ?

This gem allow you to use activerecord + mysql2 with fibers, the old em_mysql2 driver from the mysql2 gem was use as a foundation.

Why ?

The "new" em_mysql2 driver lives in em-synchrony but it is far from prefect, instead of trying to keep the same behavior as the threaded version it just patch activerecord enough to make it work.

I don't pretend my implementation is perfect but at least I try to keep the same behavior.

Supported ActiveRecord version

This gem currently support 4.0.0

Example:

require 'rubygems'
require 'bundler/setup'

require 'active_record'
require 'em-mysql2'

ActiveRecord::Base.establish_connection(
  adapter:          'em_mysql2',
  database:         'test',
  username:         'root',
  pool:             2,
  checkout_timeout: 30,
  socket:           '/tmp/mysql_ram.sock'
)

ActiveRecord::Base.logger = Logger.new($stdout)

COUNT = 5
started_at = Time.now

EM::run do
  left = COUNT
  
  
  COUNT.times do |n|
    Fiber.new do
      
      ActiveRecord::Base.connection_pool.with_connection do
        ActiveRecord::Base.connection.execute("SELECT SLEEP(2)")
      end
      
      left -= 1
      if left <= 0
        EM::stop()
      end
    end.resume
  end
  
  
end


elapsed = (Time.now - started_at)
puts "time: #{'%.2f' % elapsed} seconds"

em-mysql2's People

Contributors

ahorek avatar schmurfy avatar

Watchers

 avatar  avatar  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.