Skip to content

Instantly share code, notes, and snippets.

@pmahoney
pmahoney / gist:1970815
Created March 4, 2012 05:28
Jenkins and Java fork()+exec() out of memory

Orien is correct, it is the fork() system call triggered by ProcessBuilder or Runtime.exec or other means of the JVM executing an external process (e.g. another JVM running ant, a git command, etc.).

There have been some posts on the Jenkins mailing lists about this: Cannot run program "git" ... error=12, Cannot allocate memory

There is a nice description of the issue on the SCons dev list: fork()+exec() vs posix_spawn()

There is a long standing JVM bug report with solutions: Use posix_spawn, not fork, on S10 to avoid swap exhaustion. But I'm not sure if this actually made it into JDK7 as the comments suggest was the plan.

In summary, on Unix-like systems, when one process (e.g. the JVM) needs to launch another process (e.g. git) a system call is made to

@pmahoney
pmahoney / become_java_test.rb
Last active March 15, 2023 00:45
Test of become_java! and having java code call a ruby object.
require 'jruby/core_ext'
class MyObserver
include Java::JavaUtil::Observer
def update(observable, arg)
puts "UPDATE! #{observable}"
end
end
MyObserver.become_java! false
@pmahoney
pmahoney / Dockerfile
Last active August 14, 2019 18:30
kidn - k3s in dockerd's namespaces
FROM busybox:1.31.0
ENTRYPOINT ["echo", "it worked"]
@pmahoney
pmahoney / executor.rb
Created October 3, 2012 20:50
executors in jruby example
require 'java'
class Task
include Java::JavaUtilConcurrent::Callable
def initialize(num)
@num = num
end
def call
require 'bundler'
# First attempt a bundle install without remote resolution. In the
# happy case, all gems are already installed, and checking this is
# quick. If it fails, attempt a remote resolution. This is slow
# (probably largely because of how many dang gem versions we have in
# our local gem server), but it will install anything that is missing.
#
# Bundler uses lots of class-level configuration, and thus isn't
# designed to be called repeatedly with different options, but we're
require 'benchmark'
A = 'a'
B = 'b'
C = 'c'
D = 'd'
E = 'e'
F = 'f'
G = 'g'
H = 'h'
@pmahoney
pmahoney / benchmarks
Created December 7, 2012 16:55
Assets precompilation benchmark
See https://github.com/pmahoney/assets_comp_perf
rails 3.2.9, hike 1.2.1, sprockets 2.2.2
* denotes best time
Ruby 1.9.3-p194
$ time bundle exec rake assets:clean assets:precompile
@pmahoney
pmahoney / comments
Created November 1, 2012 21:30
JRuby $LOAD_PATH index speeds up Bundler.require in a Rails app (at top of application.rb)
Rails 3.1.8 app in Ruby 1.8 compatibility mode with ~65 dependencies
(not sure how many in total including
transient deps) was timed up to the Bundler.require line in config/application.rb
(JRuby 1.7.0)
Before: 18.8 seconds
After: 15.9 seconds
This likely seriously breaks the semantics of 'require', and maybe isn't faster
enough to be worth it.
this SunJCE_y (id=144)
arg0 true
arg1 "DESede/CBC/PKCS5Padding" (id=249)
arg2 (id=254)
@pmahoney
pmahoney / Time.java
Created October 18, 2012 17:29
RubyTime opPlusNanos maybe
public class Time {
private final long timeInMillis;
private final long nsec;
public Time(long timeInMillis, long nsec) {
this.timeInMillis = timeInMillis;
this.nsec = nsec;
}