jemalloc 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ *.o
2
+ *.so
3
+ *~
4
+ ext/jemalloc/*.c
5
+ ext/jemalloc/jemalloc-3.0.0/
6
+ ruby/Makefile
7
+ *.5
8
+ *.8
9
+ *.6
10
+ _obj
11
+ _test
data/ChangeLog ADDED
@@ -0,0 +1,9 @@
1
+ Release 0.1.4 - 2012/10/21
2
+ - change gem name from 'je' to 'jemalloc'
3
+
4
+ Release 0.1.3 - 2012/10/16
5
+ - jemalloc v3.1.0
6
+
7
+ Release 0.1.2 - 2012/09/19
8
+ - support -v option
9
+ - jemalloc v3.0.0
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source :rubygems
2
+ gemspec
3
+
4
+ group :compilation do
5
+ gem 'rake-compiler', '~> 0.7.1'
6
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,20 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ jemalloc (0.1.4)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ rake (0.9.2.2)
10
+ rake-compiler (0.7.9)
11
+ rake
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ bundler (>= 1.0.0)
18
+ jemalloc!
19
+ rake (>= 0.8.7)
20
+ rake-compiler (~> 0.7.1)
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # je
2
+
3
+ Instant [jemalloc](http://www.canonware.com/jemalloc/) injection into Ruby apps, for better performance and less memory.
4
+
5
+ # Why jemalloc?
6
+
7
+ Ruby relies on malloc(3) for its internal memory allocation. Using better malloc() implementation will boost your application performance, and supress the memory usage.
8
+
9
+ jemalloc is a malloc(3) implementation, originally developed by Jason Evans. jemalloc handles small object better than other allocators so usually gives better performance and memory usage to Ruby programs.
10
+
11
+ # Why je?
12
+
13
+ Installing jemalloc separately from Ruby is pain in some cases (e.g. Heroku, EngineYard, etc). `je` gem contains jemalloc itself within a gem, and enables instant jemalloc ingection in a really easy way: install `je` gem, and launch your app with `je` command.
14
+
15
+ # Install
16
+
17
+ Install `je` gem in your application. For [bundler](http://gembundler.com/) based application, please add the following line into your Gemfile, and and install `je` by `bundle install`.
18
+
19
+ gem 'je'
20
+
21
+ # Usage
22
+
23
+ Execute your application with `je` command, which is contained in `je` gem. Example command for Rails + bundler application is like follows.
24
+
25
+ $ bundle exec je ./script/rails s
26
+
27
+ `-v` option will let you confirm jemalloc is actually injected.
28
+
29
+ $ bundle exec je -v ./script/rails s
30
+ => Injecting jemalloc...
31
+ => Booting WEBrick
32
+ ...
33
+
34
+ # Limitation
35
+
36
+ Currently, this gem works only on Linux and Mac OS X.
37
+
38
+ # License
39
+
40
+ [BSD-derived License](http://www.canonware.com/jemalloc/license.html).
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ # -*- mode: ruby; coding: utf-8 -*-
2
+ require 'rubygems'
3
+ require 'bundler'
4
+
5
+ require 'rake'
6
+ require 'rake/clean'
7
+ require 'rake/testtask'
8
+ require 'rubygems/package_task'
9
+
10
+ Bundler::GemHelper.install_tasks
11
+
12
+ begin
13
+ require 'rake/extensiontask'
14
+ Rake::ExtensionTask.new('jemalloc')
15
+ rescue LoadError
16
+ abort "This Rakefile requires rake-compiler (gem install rake-compiler)"
17
+ end
data/bin/je ADDED
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+ require 'timeout'
4
+
5
+ # Help
6
+ def usage
7
+ puts <<END
8
+ Usage: je [ARGS]...
9
+
10
+ Options:
11
+ -v verbose
12
+ END
13
+ exit
14
+ end
15
+
16
+ # Option parsing
17
+ $verbose = false
18
+ argv = ARGV
19
+ usage() if argv.length == 0
20
+ if argv[0] == '-v'
21
+ $verbose = true
22
+ argv = argv[1..-1]
23
+ end
24
+ usage() if argv.length == 0
25
+
26
+ # Set ENV for preloading jemalloc
27
+ lib_dir = File.expand_path('../lib/', File.dirname(__FILE__))
28
+ if File.exists? (lib_dir + "/jemalloc.so")
29
+ puts "=> Injecting jemalloc..." if $verbose
30
+ ENV.store("LD_PRELOAD", lib_dir + "/jemalloc.so")
31
+ elsif File.exists? (lib_dir + "/jemalloc.bundle")
32
+ puts "=> Injecting jemalloc..." if $verbose
33
+ ENV.store("DYLD_INSERT_LIBRARIES", lib_dir + "/jemalloc.bundle")
34
+ else
35
+ puts "=> Skip injecting jemalloc. Your platform is not supported." if $verbose
36
+ end
37
+
38
+ # fork(2)
39
+ pid = Process.fork
40
+
41
+ # set signal handlerss
42
+ def terminate_gracefully(pid)
43
+ begin
44
+ Process.kill("SIGTERM", pid) rescue Errno::ESRCH
45
+ Timeout.timeout(3) {
46
+ pid, status = Process.wait2
47
+ Kernel.exit (status.exitstatus || 0)
48
+ }
49
+ rescue Timeout::Error
50
+ Process.kill("SIGKILL", pid) rescue Errno::ESRCH
51
+ end
52
+ end
53
+ trap("INT") { puts "SIGINT received"; terminate_gracefully pid }
54
+ trap("TERM") { puts "SIGTERM received"; terminate_gracefully pid }
55
+
56
+ # exec(2)
57
+ if pid.nil? then
58
+ Kernel.exec *argv
59
+ else
60
+ pid, status = Process.wait2
61
+ Kernel.exit (status.exitstatus || 0)
62
+ end
@@ -0,0 +1,42 @@
1
+ require 'mkmf'
2
+ require 'rbconfig'
3
+
4
+ $stdout.sync = true
5
+ pkg = "jemalloc-3.1.0"
6
+
7
+ # monfigure and copy sources to cur_dir
8
+ cur_dir = Dir.pwd
9
+ Dir.chdir File.dirname(__FILE__) do
10
+ # cleanup
11
+ puts `rm -fR #{pkg}`
12
+ puts `tar vjxf #{pkg}.tar.bz2`
13
+ Dir.chdir(pkg) do
14
+ # configure
15
+ puts `./configure`
16
+ # zone.c is only for Mac OS X
17
+ if RbConfig::CONFIG['target_vendor'] != "apple"
18
+ puts `rm -fR src/zone.c`
19
+ end
20
+ # mkmf only allows *.c files on current dir
21
+ puts `cp src/*.c #{cur_dir}`
22
+ end
23
+ end
24
+ Dir.chdir cur_dir
25
+
26
+ include_dir= File.dirname(__FILE__) + "/#{pkg}/include/"
27
+ $CFLAGS << %[ -std=gnu99 -Wall -pipe -g3 -fvisibility=hidden -O3 -funroll-loops -D_GNU_SOURCE -D_REENTRANT -I.. -I#{include_dir}]
28
+
29
+ create_makefile('jemalloc')
30
+
31
+ # modify Makefile to create .dylib, instead of .bundle
32
+ # NOTICE: Mac OS X only
33
+ if RbConfig::CONFIG['target_vendor'] == "apple"
34
+ makefile = open('Makefile').read
35
+ if makefile =~ /-dynamic\ -bundle/ && makefile =~ /-flat_namespace/
36
+ makefile.gsub!(/-dynamic\ -bundle/, '-shared')
37
+ makefile.gsub!(/-flat_namespace/, '-dylib_install_name')
38
+ else
39
+ raise 'Your platform is not supported. Please report to http://github.com/treasure-data/je'
40
+ end
41
+ open('Makefile', 'w'){ |f| f.write(makefile) }
42
+ end
Binary file
data/jemalloc.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # -*- mode: ruby; coding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require 'jemalloc/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "jemalloc"
7
+ s.version = JEMalloc::VERSION
8
+ s.summary = "use jemalloc as default allocator, everywhere!"
9
+ s.description = %q{Use jemalloc as default allocator, everywhere!}
10
+ s.author = "Kazuki Ohta"
11
+ s.email = "kazuki.ohta@gmail.com"
12
+ s.homepage = "https://github.com/treasure-data/je"
13
+ s.extensions = ["ext/jemalloc/extconf.rb"]
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_development_dependency 'bundler', ['>= 1.0.0']
21
+ s.add_development_dependency 'rake', ['>= 0.8.7']
22
+ s.add_development_dependency 'rake-compiler', ['~> 0.7.1']
23
+ end
@@ -0,0 +1,3 @@
1
+ module JEMalloc
2
+ VERSION = "0.1.4"
3
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jemalloc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kazuki Ohta
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.0.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 0.8.7
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.8.7
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake-compiler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.7.1
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.7.1
62
+ description: Use jemalloc as default allocator, everywhere!
63
+ email: kazuki.ohta@gmail.com
64
+ executables:
65
+ - je
66
+ extensions:
67
+ - ext/jemalloc/extconf.rb
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - ChangeLog
72
+ - Gemfile
73
+ - Gemfile.lock
74
+ - README.md
75
+ - Rakefile
76
+ - bin/je
77
+ - ext/jemalloc/extconf.rb
78
+ - ext/jemalloc/jemalloc-3.1.0.tar.bz2
79
+ - jemalloc.gemspec
80
+ - lib/jemalloc/version.rb
81
+ homepage: https://github.com/treasure-data/je
82
+ licenses: []
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ segments:
94
+ - 0
95
+ hash: -600800011442930264
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ segments:
103
+ - 0
104
+ hash: -600800011442930264
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 1.8.24
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: use jemalloc as default allocator, everywhere!
111
+ test_files: []