libgfapi-ruby
Ruby bindings for libgfapi (GlusterFS API).
Installation
Add this line to your application's Gemfile:
gem 'libgfapi-ruby'
And then execute:
$ bundle
Or install it yourself as:
$ gem install libgfapi-ruby
Usage
require 'glusterfs'
# Create virtual mount
volume = GlusterFS::Volume.new('my_volume')
volume.mount('1.2.3.4')
# Create a new directory
dir = GlusterFS::Directory.new(volume, '/some_dir')
dir.create
# Delete a directory
dir = GlusterFS::Directory.new(volume, '/some_dir')
dir.delete
# or
volume.delete_dir('/some_dir')
# Create a file from string or bytes
file = GlusterFS::File.new(volume, '/gfs/file/path')
size = file.write(data)
puts "Written #{size} bytes"
# Copy an existing file to gluster
existing_file = File.open('/path/to/file')
file = GlusterFS::File.new(volume, '/gfs/file/path')
size = file.write_file(existing_file)
puts "Written #{size} bytes"
# Read a file
file = GlusterFS::File.new(volume, '/gfs/file/path')
contents = file.read
# Read a file into a Tempfile
file = GlusterFS::File.new(volume, '/gfs/file/path')
tempfile = file.read_file
puts "Tempfile path: #{tempfile.path}"
# Delete a file
file = GlusterFS::File.new(volume, '/gfs/file/path')
file.delete
# or
volume.delete_file('/gfs/file/path')
# Unmount virtual mount
volume.unmount
Troubleshooting
- If volume mount fails, you may need to set volume
option
to allow insecure RPC (
rpc-auth-allow-insecure on
). - If you get a SEGFAULT, it most likely means you're trying to do something without checking if
it's possible, i.e.:
- Create a directory
/foo/bar
while/foo
does not exist. - Write a file
/foo/bar/baz.txt
while/foo/bar
directory does not exit.
- Create a directory
Running Specs
Run specs with rake spec
. However, you need glusterfs-server running somewhere, and a test mount.
If you have it in the computer you want to run your tests at (Vagrant works fine), you can do this:
- Add
127.0.0.1 distfs
to/etc/hosts
- Run
gluster volume create dist-volume distfs:/dist1 force
- Run
gluster volume start dist-volume
- Run
rake spec
Another option - use existing cluster, set following env variables before running tests:
export GFS_VOLUME='volume-name'
export GFS_SERVER_HOST='1.2.3.4'
export GFS_SERVER_PORT=24007
rake spec
Performance
There is performance spec: spec/glusterfs/stress/performance_spec.rb
. You can edit values at
spec/spec_helper.rb
or provide ENV variables to run it on your system. Here's how 1000 iterations
of create/delete directories with various file sizes looks like:
# 5 Kb files
Native FS Time: 1000 iterations: 0.1400 sec
Mounted FS Time: 1000 iterations: 44.0874 sec
GFS API Time: 1000 iterations: 42.4865 sec
# 70 Kb files
Native FS Time: 1000 iterations: 0.6270 sec
Mounted FS Time: 1000 iterations: 79.2414 sec
GFS API Time: 1000 iterations: 46.4481 sec
# 5 Mb files
Native FS Time: 1000 iterations: 6.1057 sec
Mounted FS Time: 1000 iterations: 94.8507 sec
GFS API Time: 1000 iterations: 118.8812 sec
Tests were run on CentOS with Intel(R) Xeon(R) CPU E5-2407 0 @ 2.20GHz, 128GB RAM, with following GlusterFS Volume configuration:
Volume Name: dist-volume
Type: Replicate
Volume ID: <skipped>
Status: Started
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: server1:/var/lib/gfs/dist-volume
Brick2: server2:/var/lib/gfs/dist-volume
Options Reconfigured:
server.allow-insecure: on
features.worm: disable
network.frame-timeout: 10
diagnostics.latency-measurement: on
performance.cache-size: 1024MB
cluster.data-self-heal-algorithm: full
nfs.disable: yes
performance.write-behind-window-size: 128MB
performance.cache-refresh-timeout: 10
TODO
Major things missing:
- Directory listing / traversal
Known issues
GlusterFS::Volume.mount / unmount
leaks
memory.
Contributing
- Fork it ( http://github.com/spajus/libgfapi-ruby/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request