Created
September 1, 2010 01:34
-
-
Save raggi/560087 to your computer and use it in GitHub Desktop.
the secrets of the web scale sauce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'eventmachine' | |
EM.run do | |
SEKRET_SAUCE = EM.attach( | |
open(RUBY_PLATFORM =~ /mswin|mingw/ ? 'NUL:' : '/dev/null', 'w') | |
) | |
EM.start_server('0.0.0.0', 80, Module.new do | |
def post_init; proxy_incoming_to(SEKRET_SAUCE); end | |
end) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'socket' | |
SEKRET_SAUCE = open RUBY_PLATFORM =~ /mswin|mingw/ ? 'NUL:' : '/dev/null', 'w' | |
Socket.tcp_server_loop(80) do |client| | |
Thread.new { IO.copy_stream(client, SEKRET_SAUCE) } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
abort 'Usage: shardnull path num_shards' unless ARGV.size == 2 | |
abort 'shardnull must be run as root' unless Process.uid == 0 | |
require 'rubygems' | |
require 'ffi' | |
class File | |
extend FFI::Library | |
ffi_lib 'c' | |
attach_function :mknod, [ :string, :int, :int ], :bool | |
attach_function :perror, [ :string ], :void | |
end | |
path, num_shards = *ARGV | |
shards = Array.new(num_shards.to_i) { |n| File.join(path, "null#{n}") } | |
shards.each do |path| | |
if File.mknod(path, 020666, File.stat('/dev/null').rdev) | |
File.perror("Error making #{path}") | |
abort | |
end | |
# modes are set via umask (laaame), so we have to open this up here: | |
File.chmod 0666, path | |
puts path | |
end |
SCALING BRO. HOW DO YOU DO IT? 🤘
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Holy shit, you literally sharded /dev/null