Skip to content

Instantly share code, notes, and snippets.

💭
becoming dark matter - one commit at a time

Karol Bucek kares

💭
becoming dark matter - one commit at a time
Block or report user

Report or block kares

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@kares
kares / stack.dump
Created Jan 24, 2019
left-over threads
View stack.dump
Thread 0x1a1962 ():
/usr/local/rvm/rubies/jruby-9.1.17.0/lib/ruby/stdlib/monitor.rb:111:in `wait'
/usr/local/rvm/rubies/jruby-9.1.17.0/lib/ruby/stdlib/monitor.rb:111:in `wait'
/srv/phone/apptastic/shared/bundle/jruby/2.3.0/gems/future-resource-1.1.0/lib/future-resource.rb:66:in `resource'
/usr/local/rvm/rubies/jruby-9.1.17.0/lib/ruby/stdlib/monitor.rb:214:in `mon_synchronize'
/srv/phone/apptastic/shared/bundle/jruby/2.3.0/gems/future-resource-1.1.0/lib/future-resource.rb:65:in `resource'
/srv/phone/apptastic/shared/bundle/jruby/2.3.0/gems/future-resource-1.1.0/lib/future-resource.rb:64:in `timeout'
/srv/phone/apptastic/shared/bundle/jruby/2.3.0/gems/future-resource-1.1.0/lib/future-resource.rb:64:in `resource'
/srv/phone/apptastic/shared/bundle/jruby/2.3.0/bundler/gems/adhearsion-2676734110e0/lib/adhearsion/rayo/component/component_node.rb:56:in `complete_event'
/srv/phone/apptastic/shared/bundle/jruby/2.3.0/bundler/gems/adhearsion-2676734110e0/lib/adhearsion/call_controller.rb:230:in `execute_compon
@kares
kares / monitor_daemon.rb
Created Jan 23, 2019
Daemon thread that logs memory usage an load (for JRuby)
View monitor_daemon.rb
require 'logger'
class MonitorDaemon
LOG_FILE = 'monitor.log'
LOG_FILES_MAX = 10 * 1024 * 1024 # 10MB
LOG_FILES_KEEP = 10 # keep 10 (max 100MB)
LOGGER = begin
if $servlet_context && ENV_JAVA['catalina.base'] && # {tomcat_base}/logs
@kares
kares / assets.rb
Last active Nov 29, 2016
SASS (asset) path/url functions patch to make sure non absolute /assets URLs are returned (e.g. for bootstrap-sass)
View assets.rb
if File.basename($0) == 'rake' && ARGV.include?('assets:precompile') # Rails.env.production?
puts "patching sass functions to return relative asset paths" if $VERBOSE
begin
require 'sprockets/sass/functions'
sass_functions = Sprockets::Sass::Functions
Autoload::Sass::Script rescue nil # loading
rescue LoadError # 2.x
require 'sprockets/sass_functions'
@kares
kares / heap-dump.backtrace.js
Last active Nov 24, 2016
Extract relevant (partial backtrace) information from heap-dump using OQL
View heap-dump.backtrace.js
map( heap.objects('org.jruby.runtime.ThreadContext'), function(ctx) {
var str = toHtml(ctx) + " oid: " + objectid(ctx);
str += " ";
var toHtmlObj = function(obj) { return "<br> " + toHtml(obj); };
try {
//return str + doObjPath(ctx, toHtmlObj, 'thread', 'threadImpl', 'nativeThread', 'referent');
str += resolveObjPath(ctx, 'thread', 'threadImpl', 'nativeThread', 'referent', 'name').toString();
str += '<br> backtraceIndex = ' + ctx.backtraceIndex;
@kares
kares / slow_query_log.rb
Last active Jan 10, 2019
ActiveRecord slow query logging in Rails ... setup using: config.slow_query_log_threshold_in_ms = 500
View slow_query_log.rb
require 'active_record/log_subscriber'
class SlowQueryLog < ActiveSupport::LogSubscriber
if Rails.configuration.respond_to?(:slow_query_log_threshold_in_ms)
if @@threshold = Rails.configuration.slow_query_log_threshold_in_ms
@@threshold = @@threshold.to_i == 0 ? nil : @@threshold.to_i
end
else
@@threshold = nil
@kares
kares / memory_monitor_daemon.rb
Last active Nov 16, 2016
periodically print JVM memory usage and load
View memory_monitor_daemon.rb
require 'logger'
Class.new do
LOGGER = Logger.new(STDOUT)
# Logger.new File.open('jmx.log', File::WRONLY | File::APPEND)
def initialize; @done = nil end
def start
@kares
kares / thread_group_list.rb
Created Feb 7, 2016
ThreadGroup#list patch for JRuby 1.7.4 (-1.7.18)
View thread_group_list.rb
if JRUBY_VERSION < '1.7.19'
require 'thread'; require 'java'
org.jruby.RubyThreadGroup.field_reader :rubyThreadList
ThreadGroup.class_eval do
def list
threads = []
list = to_java.rubyThreadList
list.synchronized do # iterator must be sync-ed
list.each { |t| threads << t if t }
end
@kares
kares / password.rb
Created Jan 12, 2016 — forked from steakknife/password.rb
get password - Ruby - any platform - no gems needed
View password.rb
# Copyright 2012-2013 Barry Allard <barry.allard@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
@kares
kares / current_thread_aware_formatter.rb
Created Oct 19, 2015
Logger::Formatter aware of Thread.current for JRuby
View current_thread_aware_formatter.rb
require 'jruby'
class CurrentThreadAwareFormatter < Logger::Formatter
FORMAT = "%s [%5s] {%s} -- %s\n".freeze
def call(severity, time, progname, msg)
thread = Thread.current
thread_id = JRuby.reference(thread).getNativeThread.to_s
thread_id << ' ' << ( thread[:name] || thread.to_s )
FORMAT % [format_datetime(time), severity, thread_id, msg2str(msg)]
end
end
@kares
kares / pool.rb
Last active Oct 14, 2015
AR 3.2 pool patch for less contention on release_connection
View pool.rb
::ActiveRecord::ConnectionAdapters::ConnectionPool.class_eval do
def release_connection(with_id = current_connection_id)
#synchronize do
conn = @reserved_connections.delete(with_id)
checkin conn, true if conn
#end
end
def checkin(conn, on_release = nil)
You can’t perform that action at this time.