Skip to content

Instantly share code, notes, and snippets.

View jrafanie's full-sized avatar

Joe Rafaniello jrafanie

  • New Jersey
View GitHub Profile
@jrafanie
jrafanie / gist:dac5e3aa4e58dbc523d5
Created October 20, 2014 15:27
Killing postgres connections on edge rails doesn't retry user's requests
1) Backend postgres is killed:
03:27:13 ~/Code/rails42edge_app (2.0.0-p576) + be rails c
Warning: You're using Rubygems 2.0.14 with Spring. Upgrade to at least Rubygems 2.1.0 and run `gem pristine --all` for better startup performance.
Loading development environment (Rails 4.2.0.beta2)
irb(main):001:0> conn = ActiveRecord::Base.connection;
irb(main):002:0* conn.query("SELECT pg_backend_pid()").first.first
(0.2ms) SELECT pg_backend_pid()
=> "99609"
irb(main):003:0> Process.kill("KILL", 99609)
@jrafanie
jrafanie / gist:f6a00e0f17e5fd621d52
Created November 19, 2014 16:20
configure on trunk ruby
checking for pthread_attr_setinheritsched... yes
checking for pthread_getattr_np... no
checking for pthread_attr_get_np... no
checking for pthread_attr_getstack... yes
checking for pthread_get_stackaddr_np... yes
checking for pthread_get_stacksize_np... yes
checking for thr_stksegment... no
checking for pthread_stackseg_np... no
checking for pthread_getthrds_np... no
checking for pthread_cond_init... yes
@jrafanie
jrafanie / gist:22068ed38351ad394848
Created November 24, 2014 21:00
gem-compare of several bundler versions
gem install gem-compare
gem compare bundler 1.7.4 1.7.5 1.7.6 1.7.7
Fetching: bundler-1.7.4.gem (100%)
Fetching: bundler-1.7.5.gem (100%)
Fetching: bundler-1.7.6.gem (100%)
Fetching: bundler-1.7.7.gem (100%)
Compared versions: ["1.7.4", "1.7.5", "1.7.6", "1.7.7"]
DIFFERENT date:
1.7.4: 2014-10-20 00:00:00 UTC
1.7.5: 2014-11-11 00:00:00 UTC
@jrafanie
jrafanie / gist:0163a705d7129e1d560f
Last active August 29, 2015 14:11
post-checkout
#!/bin/sh
#
# Put this in manageiq/.git/hooks/post-checkout
# Make sure you chmod +x !!!
#
# Swap a Rails 4 Gemfile.lock on checkout of rails4 branch
# Put back the master branch Gemfile.lock when checking out a non-"rails4" branch.
#
branch=$(git symbolic-ref -q --short HEAD)
if [ "$branch" = "rails4" ]
@jrafanie
jrafanie / gist:f9d5f4206542def27ebf
Created February 11, 2015 21:46
Bundler::GemfileNotFound: Could not locate Gemfile errors with bundler 1.8.0 and rubygems 2.0.14
04:11:57 ~/Code/manageiq/vmdb (master) (2.0.0-p594) + ruby -v; gem --version; bundle --version; time bundle install --without test:metric_fu:development:qpid --jobs 4
ruby 2.0.0p594 (2014-10-27) [x86_64-darwin13.4.0]
2.0.14
Bundler version 1.8.0
Fetching source index from https://rubygems.org/
Fetching git://github.com/ManageIQ/rails.git
Fetching git://github.com/ManageIQ/actionwebservice.git
Fetching git://github.com/ManageIQ/handsoap.git
Fetching https://github.com/amatsuda/jquery-rjs.git
Fetching git://github.com/ManageIQ/rubyrep.git
@jrafanie
jrafanie / gist:1c9e99a35ddc11a9343b
Created February 12, 2015 16:55
rubygems 2.4.5+ bundler 1.8.0 + ruby 2.1.5 + bundle install --jobs=4 results in random "Bundler::GemfileNotFound: Could not locate Gemfile" errors
11:46:04 ~/Code/manageiq/vmdb (master) (2.1.5) - rm -rf ~/.gem/ruby/2.1.5
11:46:12 ~/Code/manageiq/vmdb (master) (2.1.5) + gem install bundler -v1.8.0
Fetching: bundler-1.8.0.gem (100%)
Successfully installed bundler-1.8.0
1 gem installed
11:46:29 ~/Code/manageiq/vmdb (master) (2.1.5) + gem update --system
Updating rubygems-update
Fetching: rubygems-update-2.4.5.gem (100%)
Successfully installed rubygems-update-2.4.5
Installing RubyGems 2.4.5
@jrafanie
jrafanie / gist:00e52ead2f39124ce1d5
Created March 2, 2015 17:11
ManageIQ - Top 200 slowest example groups (by total time)
Top 200 slowest example groups (by total time):
ApiController
0.35133 seconds average (33.73 seconds / 96 examples) ./spec/requests/api/policies_assignment_spec.rb:20
VmdbwsController
0.44243 seconds average (29.64 seconds / 67 examples) ./spec/apis/vmdbws_inventory_spec.rb:3
MiqAeDatastore
0.32243 seconds average (20.31 seconds / 63 examples) ./spec/models/miq_ae_yaml_import_export_spec.rb:4
MiqAeStateMachine
2.47 seconds average (19.75 seconds / 8 examples) ./spec/lib/miq_automation_engine/miq_ae_state_machine_spec.rb:5
ApiController
@jrafanie
jrafanie / gist:8256d85bd439b0750d7a
Created March 12, 2015 16:02
Using OSX's say and bash to find a rspec seed to recreate test order dependency bugs
#!/bin/bash
#
# usage:
# Pass the tests/directories you want to tests in random order:
# ./test_until_failure.sh spec/models"`
#
# For example, if you think the connections method is suspect:
# ./test_until_failure.sh `git grep -l connections spec/lib spec/models/ spec/controllers/ |grep "_spec.rb"`
for i in `seq 1 500`;
do
@jrafanie
jrafanie / output.sh
Created April 6, 2015 21:40
Detect binary gems in your bundle programmatically
bundle package # downloads all .gem files in your bundle to vendor/cache
# use gem spec A.gem extensions to print the extensions property in the gemspec
for i in `ls vendor/cache`; do echo $i; gem spec vendor/cache/$i extensions; done
CFPropertyList-2.3.0.gem
--- []
Platform-0.4.0.gem
--- []
@jrafanie
jrafanie / a_summary.md
Last active August 29, 2015 14:20
Require timing logging with virtual memory logging

We were seeing 500+ MB of increased virtual memory usage compared to older versions of ManageIQ per process.

Using ManageIQ and require logging, we can measure how long and how much memory EACH require takes:

REQUIRE_LOG=true bin/rails r ""

This writes a log file in vmdb/log/require_DATEXYZ.log.

Note, require_with_logging is required in the preinitializer.rb