Skip to content

Instantly share code, notes, and snippets.

View kares's full-sized avatar
💤

Karol Bucek kares

💤
View GitHub Profile
@kares
kares / memory_monitor_daemon.rb
Last active November 16, 2016 15:42
periodically print JVM memory usage and load
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 February 7, 2016 13:05
ThreadGroup#list patch for JRuby 1.7.4 (-1.7.18)
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 January 12, 2016 08:53
get password - Ruby - any platform - no gems needed
# 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 October 19, 2015 13:08
Logger::Formatter aware of Thread.current for JRuby
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 October 14, 2015 17:47
AR 3.2 pool patch for less contention on release_connection
::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)
@kares
kares / celluloid.rb
Last active August 29, 2015 14:13
celluloid InternalPool backport from master (due inproper synchronization) http://git.io/9NV23Q
require 'celluloid/internal_pool'
# NOTE: this also avoids JRuby bug with ThreadGroup#list !
# require 'celluloid' likely happened already :
if Celluloid.internal_pool
Celluloid.internal_pool.shutdown
Celluloid.internal_pool = nil
end
require 'logging'
module Logging
# require 'logging/repository'
# class Repository
# # include Singleton
#
# def initialize; require 'thread_safe'
# # @h = {:root => ::Logging::RootLogger.new}
# @h = ThreadSafe::Cache.new
@kares
kares / celluloid_stack_dump.rb
Created December 22, 2014 15:09
Celluloid.stack_dump tunings on JRuby
require 'celluloid/stack_dump'
module Celluloid
class StackDump
class ActorState
attr_accessor :thread_name, :thread_id
def dump
@kares
kares / benchmark_java_lang_System_getProperty.rb
Created December 3, 2014 10:51
JRuby 1.7.16 benchmark for java.lang.System.getProperty
require 'benchmark'
TIMES = 10_000
Benchmark.bmbm do |x|
x.report("java.lang.System.get_property [#{TIMES}x]") do
TIMES.times do
java.lang.System.get_property('jars.skip') == 'true'
end
@kares
kares / changes.md
Last active August 29, 2015 14:10
JRuby - (mostly) some of the concurrency related - changes since 1.7.4