This document discusses using Ruby on embedded devices. It notes that while Ruby has good network libraries and is platform independent, using gems can be problematic due to dependencies. It recommends using alternative languages for specific tasks, like C for performance critical code, Bash for portable scripts, Flex for pattern matching, and Go for networking. It also recommends using jit to compile scripts to native binaries for performance. The document promotes UN*X tools over rebuilding functionality in Ruby and ends by mentioning they are crowdfunding their project at https://getkinko.com.
3. What is kinko.me
4 PGP-based email encryption
4 for your desktop and your mobiles
4 with your current email address
Also
4 comes on a dedicated device
4. ssshhh...
as of this afternoon we are crowdfunding.
Feel invited to check https://getkinko.com
6. Compared to modern machines
4 CPU: 10x
4 IO throughput: ~50x
(RAM is ok, though)
7. Is this good enough?
4 Compared to Intel 386: yes
4 Compared with servers: a different usage
patterns
4 low traffic volume
4 few requests to HTTPS frontend
14. gems + bundler
gems, bundler and all that mess
4 gems are platform independent. Well,
mostly.
4 bundler: hard to manage over accounts
15. Performance
4 once started performance is ok:
4 ~10 to 20 pages rendered per second
4 startup performance is really bad:
4 starting a sinatra/ActiveRecord app:
~15 seconds
20. UN*X is your friend
4 caching: file system cache
4 resources: cleans up after you
4 shared storage: file system
4 built-in authentication: users + groups
4 also: ulimit, chroot, etc.
21. ... Don't rebuild it in ruby
A custom logger in ruby:
logger = Logger.new("#{Rails.root}/log/custom.log", 'daily')
logger.formatter = proc do |severity, time, _, msg|
"#{time.strftime("%B %d %H:%M:%S")} #{severity} #{msg}n"
end
config.logger = logger
22. ... Don't rebuild it in ruby, pt. 2
A custom logger in external application:
reader, writer = IO.pipe
fork do
Process.setpgrp
STDIN.reopen reader
writer.close
exec("timestamp")
end
STDOUT.reopen writer
STDERR.reopen writer
reader.close
23. ... Don't rebuild it in ruby, pt. 3
or simply:
rackup 2>&1 | timestamp
24. ... Don't rebuild it
ditto:
4 daemons
4 process management
4 etc.
(Hello devops!)
26. fast and "portable": bash
#!/bin/bash
set -eu
set -o pipefail
echo "Yay!"
Commands are (sometimes) not portable:
echo -n "Is there a newline?"
27. small & fast: C
POSIX at your fingertips.
4 fast
4 small
4 source: somewhat portable; '#ifdef
linux' FTW!
28. Pattern matching: flex
Pattern matching done quickly; in portable
source code.
/* Replaces ${{NAME}} from the environment */
${{[a-zA-Z0-9_]+}} {
yytext[yyleng-2] = 0;
const char* env = yytext+3;
const char* value = getenv(env);
printf("%s", value ? value : "");
}
29. networking: Go
Go, the environment
4 fast, portable source
4 good networking + email libraries (even
SSH!)
4 crosscompiling: easy
Go, the language
4 terrible.
30. jit: Distribute scripted binaries
Use jit!
http://github.com/radiospiel/jit
4 Works with C, flex, Go
4 Compiles just in or ahead of time
4 Native speed
(Built in bash, BTW)