Skip to content

Instantly share code, notes, and snippets.

💭
looking for new opportunities - let's have them!

Karol Bucek kares

💭
looking for new opportunities - let's have them!
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 / 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)
@kares
kares / celluloid.rb
Last active Aug 29, 2015
celluloid InternalPool backport from master (due inproper synchronization) http://git.io/9NV23Q
View celluloid.rb
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
View 0_logging_unnecesary_synchronize.rb
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 Dec 22, 2014
Celluloid.stack_dump tunings on JRuby
View celluloid_stack_dump.rb
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 Dec 3, 2014
JRuby 1.7.16 benchmark for java.lang.System.getProperty
View benchmark_java_lang_System_getProperty.rb
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 Aug 29, 2015
JRuby - (mostly) some of the concurrency related - changes since 1.7.4
View changes.md
View no-conn-pool.rb
# Monkeypatch to disable connection pooling in ActiveRecord
module ActiveRecord
module ConnectionAdapters
class ConnectionPool
def checkout
c = ActiveRecord::Base.send(spec.adapter_method, spec.config.dup)
c.verify!
c
end
@kares
kares / response_process.rb
Last active Aug 29, 2015
ActionController::Live::Response partial <code>process</code> that happens on every "live" request
View response_process.rb
error = nil
# This processes the action in a child thread. It lets us return the
# response code and headers back up the rack stack, and still process
# the body in parallel with sending data to the client
Thread.new {
begin
super(name)
rescue => e
if @_response.committed?
begin
@kares
kares / serial_port_jruby.rb
Last active Aug 29, 2015
re-implementing "native" gem APIs (sample)
View serial_port_jruby.rb
# Emulates the SerialPort class that uses a native C extension.
class SerialPort < IO
load "java/jna.jar"
load "java/purejavacomm-0.0.21.jar"
java_import 'purejavacomm.CommPortIdentifier'
def initialize(port)
# do what SerialPort C does on Windows (for compat): 0 -> 'COM1'
port = "COM#{port + 1}" if port.is_a?(Integer) && windows?
You can’t perform that action at this time.