• Stars
    star
    129
  • Rank 279,262 (Top 6 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 10 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Refresh ActiveRecord connection on each rack request

activerecord-refresh_connection

Build Status Coverage Status

Refresh ActiveRecord connection on each rack request

Installation

Add the following to your Gemfile:

gem 'activerecord-refresh_connection'

And then execute:

$ bundle

How to Use

This gem provides a rack middleware ActiveRecord::ConnectionAdapters::RefreshConnectionManagement which disconnects all connections in each rack request, which results in refreshing all connections in each rack request.

Rails 5

NOTE: activerecord-refresh_connection does not work with puma, and webrick server in rails 5.

# config/application.rb
class Application < Rails::Application
  config.middleware.insert_before ActionDispatch::Executor,
    ActiveRecord::ConnectionAdapters::RefreshConnectionManagement

  ## If you would like to clear connections after 5 requests:
  # config.middleware.insert_before ActionDispatch::Executor,
  #   ActiveRecord::ConnectionAdapters::RefreshConnectionManagement, max_requests: 5
end

Middleware check.

bundle exec rake middleware

Use unicorn server to run your application.

Rails 4

NOTE: activerecord-refresh_connection does not work with puma server in rails 4.

Swap the default rails ConnectionManagement.

# config/application.rb
class Application < Rails::Application
  config.middleware.swap ActiveRecord::ConnectionAdapters::ConnectionManagement,
    "ActiveRecord::ConnectionAdapters::RefreshConnectionManagement"

  ## If you would like to clear connections after 5 requests:
  # config.middleware.insert_before ActiveRecord::ConnectionAdapters::ConnectionManagement,
  #   "ActiveRecord::ConnectionAdapters::RefreshConnectionManagement", max_requests: 5
  # config.middleware.delete ActiveRecord::ConnectionAdapters::ConnectionManagement
end

Middleware check.

bundle exec rake middleware

Sinatra

# config.ru
require 'activerecord-refresh_connection'

use ActiveRecord::ConnectionAdapters::RefreshConnectionManagement

## If you would like to clear connections after 5 requests:
# use ActiveRecord::ConnectionAdapters::RefreshConnectionManagement, max_requests: 5

run App

See Also

ChangeLog

See CHANGELOG.md for details.

Development

Run example

cd example/xxxx
bundle
bundle exec foreman start

Watch show processlist in mysql console to see connections are killed on each access.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Copyright

Copyright (c) 2014 Naotoshi Seo. See LICENSE.txt for details.

More Repositories

1

lltsv

List specified keys of LTSV (Labeled Tab Separated Values)
Go
152
star
2

fluent-plugin-record-reformer

Fluentd plugin to add or replace fields of a event record
Ruby
111
star
3

cumo

Cumo (pronounced like "koomo") is CUDA aware numerical library whose interface is highly compatible with Ruby Numo
C
92
star
4

tutorial-haartraining

Tutorial of OpenCV haartraining (Not maintained, new maintainer is wanted)
C++
84
star
5

capistrano-bundle_rsync

Deploy an application and bundled gems via rsync
Ruby
71
star
6

memprof2

Ruby memory profiler for >= Ruby 2.1.0
Ruby
67
star
7

kondate

Kondate is yet another nodes management framework for Itamae/Serverspec
Ruby
57
star
8

ruby-server-starter

a superdaemon for hot-deploying server programs (ruby port of p5-Server-Starter)
Ruby
50
star
9

isucon3_cheatsheet

cheat sheets for isucon3 middleware settings
49
star
10

haikanko

haikanko is a fluentd cluster management tool
Ruby
46
star
11

ruby-sql-maker

SQL builder for Ruby
Ruby
40
star
12

alerty

A pluggable CLI utility to send alerts if a given command failed.
Ruby
36
star
13

slack-notice-action

Yet Another GitHub Action to notify slack
TypeScript
28
star
14

daioikachan

Ikachan compatible interface with multiple backends (IRC, Slack, etc)
Ruby
28
star
15

growthforecast-tuning

GrowthForecast/RRDtool ใƒใƒฅใƒผใƒ‹ใƒณใ‚ฐ็ง˜ไผใฎๆ›ธ
27
star
16

rack-ltsv_logger

A rack middleware to output access log in ltsv format
Ruby
25
star
17

oneline_log_formatter

A ruby logger formatter to output each log in one line forcely
Ruby
22
star
18

fluentd-server

Fluentd config distribution server
Ruby
21
star
19

frontkick

Run a command with timeout, exclusive lock, and so on
Ruby
20
star
20

fluent-plugin-grep

(Deprecated) Fluentd output plugin to grep messages
Ruby
17
star
21

capistrano-colorized-stream

enables watch logs on multiple deploying hosts concurrently with colored hostnames
Ruby
17
star
22

mysql2-reconnect_with_readonly

Reconnect mysql2 if the MySQL server is running with the --read-only option
Ruby
17
star
23

gdbdump-ruby

Dump C level and Ruby level backtrace from living ruby process or core file using gdb
Ruby
15
star
24

process_safe_logger

Process-safe Logger supports log rotations in multi-processes safely
Ruby
14
star
25

fluentd-scr

fluentd source code reading
Ruby
14
star
26

embulk-filter-row

A filter plugin for Embulk to filter out rows with conditions
Java
13
star
27

cvprtoolbox-project

Real projects solving problems using https://github.com/sonots/cvprtoolbox
TeX
12
star
28

growthforecast-client

A Ruby Client Library for GrowthForecast API
Ruby
12
star
29

ltsv_log_formatter

A ruby logger formatter to output log in LTSV format
Ruby
11
star
30

resque-worker-killer

Automatically kill a child of reque worker based on max memory
Ruby
11
star
31

embulk-filter-timestamp_format

A filter plugin for Embulk to change timestamp format
Java
10
star
32

mysql_getlock

Distributed locking using mysql get_lock()
Ruby
9
star
33

fluent-plugin-named_pipe

Named pipe input/output plugin for Fluentd
Ruby
9
star
34

cvprtoolbox

Yet Another MATLAB Computer Vision and Pattern Recognition toolbox
MATLAB
9
star
35

rblineprof-report

Ruby
8
star
36

sinatra-tutorial

Ruby
8
star
37

ancestry-treeview

extension of ancestry gem to show tree view
Ruby
8
star
38

ec2-host

Search and get hosts on AWS EC2 by tags
Ruby
8
star
39

opencvx

Yet Another OpenCV eXtension
C++
7
star
40

sinatra-decorator

Decorators for Sinatra Applications
Ruby
7
star
41

fluent-plugin-reemit

Fluentd plugin to re-emit messages avoiding infinity match loop to achieve branching of data flow
Ruby
7
star
42

fluent-plugin-copy_ex

Fluentd out_copy extension
Ruby
6
star
43

resque_starter

Start and manage multiple resque workers
Ruby
6
star
44

go-sql_metrics

Instrument database/sql queries
Go
6
star
45

fluent-format

A utility to format or check fluentd configuration
Ruby
6
star
46

bundler-geminabox

Release gems to internal rubygems such as geminabox
Ruby
6
star
47

redis_getlock

Distributed locking using redis, which ensures releasing orphaned lock shortly
Ruby
6
star
48

redis_vs_q4m

benchmark to evaluate redis vs q4m as a queue engine
Ruby
5
star
49

gce-host

Search and get hosts on GCP GCE by metadata
Ruby
5
star
50

strftime_logger

A logger treats log rotation in strftime fashion
Ruby
5
star
51

isucon5_cheatsheet

5
star
52

imageclipper

A tool to crop images manually fast (not maintained)
C
5
star
53

fluent-plugin-debug

(Unmaintained) Fluentd plugin to investigate incoming messages in a short-hand
Ruby
5
star
54

embulk-parser-none

Embulk parser plugin not to parse at all
Java
4
star
55

fluent-plugin-tail_path

(Deprecated) Extension of fluentd in_tail plugin to add `path` field
Ruby
4
star
56

pukiwiki-plugin

Sonots' PukiWiki Plugin
PHP
4
star
57

bin

misc scripts
Ruby
4
star
58

rack-config_env

A rack middleware to configure rack env
Ruby
4
star
59

go-pastel

golang fork of https://github.com/bobpp/pastel, which is a copy and paste sharing web app
Go
4
star
60

ruby-capi

(Unofficial) Doxygen generated C API references of CRuby
4
star
61

redis-reconnect_with_readonly

Reconnect redis if Redis::CommandError READONLY occurs
Ruby
4
star
62

kiro

mini editor in ruby (ruby port of antirez/kilo)
Ruby
4
star
63

.dotfiles

Emacs Lisp
4
star
64

embulk-output-vertica

Embulk output plugin to load/insert data into Vertica
Ruby
4
star
65

simd-sample

Intel SSE or AVX sample
C++
3
star
66

homebrew-mycask

Personal homebrew cask repository. See https://github.com/phinze/homebrew-cask
Ruby
3
star
67

alerty-plugin-amazon_sns

Amazon SNS plugin for alerty https://github.com/sonots/alerty
Ruby
3
star
68

fluentd-plugin-ci

A repository to do bulk testing of fluentd plugins
Ruby
3
star
69

embulk-formatter-single_value

Embulk formatter plugin to output values of a single column (a kind of reverse plugin of embulk-parser-none)
Java
3
star
70

go-http_metrics

Instrument http request
Go
3
star
71

symlinks

This script makes symbolic links from files in a directory to files in a directory only if they are identical. This script would be useful to reduce storage size for daily generated documents.
Ruby
3
star
72

sinatra-template_metrics

Instrument sinatra template rendering
Ruby
3
star
73

time_with_zone

Handle time with zone without ActiveSupport or ENV['TZ']
Ruby
3
star
74

fluent-gcprofiler

Start and stop GC::Profiler from outside of fluentd
Ruby
2
star
75

resolver_replace

Replace the DNS resolver
Ruby
2
star
76

go-template_metrics

Instrument template rendering
Go
2
star
77

serf-td-agent

td-agent process management with serf
Ruby
2
star
78

kaleidoscope

Kaleidoscope: Implementing a Language with LLVM
C++
2
star
79

acts_as_file

Make your field act as a file
Ruby
2
star
80

acts_as_parameter_object

Acts as a Prameter Object. cf. Refactoring: Ruby Edition
Ruby
2
star
81

mysql2-metrics

Instrument mysql2 queries
Ruby
2
star
82

get_process_start_time

(ruby) Get process starting time (or living duration) from /proc/PID/stat
Ruby
2
star
83

reentrant_flock

A reentrant/recursive flock for ruby
Ruby
2
star
84

ruby-nogvl-sample

C
1
star
85

embulk-input-vertica

Vertica input plugins for Embulk loads records from vertica
Java
1
star
86

fluent-plugin-file2

Re-implmentation of out_file plugin for Fluentd
Ruby
1
star
87

try_rails4

my rails4 template
Ruby
1
star
88

acts_as_array

Treat your field as an array simply
Ruby
1
star
89

embulk-filter-stdout

Embulk filter plugin to print records to stdout (for debug)
Java
1
star
90

alerty-plugin-ikachan

Ikachan plugin for alerty https://github.com/sonots/alerty
Ruby
1
star
91

orb-rush-timer-twitter-bot

Perl
1
star
92

fadvise

This is a forked version of http://net.doit.wisc.edu/~plonka/fadvise/
1
star
93

ruby_bench

Benchmarks of ruby programming language
Ruby
1
star
94

stats

Calculate statistics from lines
Go
1
star
95

godenv

godenv enables to set GOPATH environment variable in each project directory.
1
star
96

hpbn-study

ใƒใ‚คใƒ‘ใƒ•ใ‚ฉใƒผใƒžใƒณใ‚นใƒ–ใƒฉใ‚ฆใ‚ถใƒใƒƒใƒˆใƒฏใƒผใ‚ญใƒณใ‚ฐ่ผช่ชญไผš่ณ‡ๆ–™(็ฌฌ10็ซ )
CSS
1
star
97

alerty-plugin-slack

Slack plugin for alerty https://github.com/sonots/alerty
Ruby
1
star
98

fluent-plugin-formatter_tsv

Fluentd TSV formatter plugin
Ruby
1
star
99

itamae-plugin-resource-daemontools_service

Itamae resource plugin to manage daemontools service
Ruby
1
star
100

pastel-cli

cli tool for pastel https://github.com/bobpp/pastel
Perl
1
star