Letsgetdugg

Random tech jargon

Browsing the tag jvm

I was recently considering trying out the new G1 garbage collector, see if it was any better than current real time CMS garbage collector. A concurrent soft real-time garbage collector that can compact? Awesome!

I switched one of my production applications to use the new G1 garbage collector and noticed a spike in CPU and diminishing throughput almost instantaniously, what gives? I googled around and stumbled upon this blog post and decided to do my own benchmarking.

I hacked up the following scala script based off the blog post to compare the two garbage collectors. The JDK that was used was JDK7u3 on Solaris on a quad core box.

val map = new java.util.LinkedHashMap[Long, String]()
var i:Long = 0
 
while(i < math.pow(10000, 2)) {
  map.put(i, new String())
  map.remove(i – 1)
  i = i + 1
  if (i % 10000 == 0) {
    System.out.println(i)
  }
}

CMS:
 
time scala -J-XX:+UseConcMarkSweepGC GC.scala
 
real    0m12.477s
user    0m12.364s
sys 0m0.491s
 
G1:
 
time scala -J-XX:+UseG1GC GC.scala
 
real    2m26.121s
user    7m33.234s
sys 0m10.888s
 
Conclusion:
 
Just what I saw with my production application, the throughput substantially diminished and the CPU cores spiked. I won’t be using the G1 garbage collector any time soon, hopefully Oracle will improve the G1 garbage collector with subsequent releases.

Tagged with , ,

Are you running JRuby in production? Do you want distributed file storage for your “enterprise” application? Look no further, MogileFS is here.

MogileFS-Client has compatibility issues with JRuby due to it’s use of the low level Socket class. JRuby 1.5-dev does not yet support all the Socket methods, so here is a monkey patch to get the ruby mogilefs client working on JRuby. Yes it blocks, but who cares JRuby has native threads.

This is exactly why I love Ruby; monkey patching.

class Socket
  def self.mogilefs_new(host,port,timeout=5.0)
    TCPSocket.open(host,port,timeout)
  end
end
class TCPSocket
  attr_accessor :mogilefs_addr, :mogilefs_connected, :mogilefs_size, :mogilefs_tcp_cork
  def self.open(host,port,timeout = 5.0)
    super(host,port.to_i)
  end
  def readable?
    true
  end
  def write_nonblock(data)
    write(data)
  end
  def recv_nonblock(size,arg)
    recv(size,arg)
  end
  def mogilefs_init(host = nil, port = nil)
    true
  end
end

Here is an example test case on how to get it all to work.

require ‘rubygems’
require ‘mogilefs’

# jmogilefs.rb is the monkey patch above
# load it after loading mogilefs client.
require ‘jmogilefs.rb’

mg = MogileFS::MogileFS.new(:domain=>‘testserv’,:hosts=>[‘xxx.xxx.xxx.xxx:6001′])

p mg.get_file_data ‘video:100:default.jpg’

p mg.get_paths ‘video:100:default.jpg’,true

mg.list_keys(‘video:100′)[0].each do |f|
 p f
end

Tagged with , ,