There are several plugins for this:
воскресенье, 26 декабря 2010 г.
понедельник, 9 ноября 2009 г.
Mongo, Mysql, Ruby and PHP
Вот тут я сравнивал MongoDB и MySQL в Ruby и результат не сильно меня обрадовал, хотя на MongoDB возлагаю большие надежды.
Я провел некоторые дополнительные бенчмарки.
Скрипты для бенчмарков тут: http://github.com/latrommi/benchmarking
Результаты ниже.
----------------------------------------------------------------
For my English friends:
Some days ago I did some MongoDB benchmark tests.
Here is more extended version.
Benchmark scripts: http://github.com/latrommi/benchmarking
and results below.
----------------------------------------------------------------
Вывод один: это не значит, что MongoDB хуже MySQL, это значит, что для нее ещё не написано нормального, быстрого драйвера для Ruby.
Conclusion: no fast Ruby driver for MongoDB.
вторник, 13 октября 2009 г.
MongoDB VS MySQL
Just insert test.
#!/usr/bin/ruby require 'rubygems' require 'benchmark' require 'mongo' require 'mysql' # init benchmark cycle def cycle 10000.times{ |i| doc = { "text" => "i am any text and a little tail with me: #{i}", "count" => i, "coords" => {"x" => 203 + i, "y" => 102 + i} } yield doc } end # init mysql mysql = Mysql.new('localhost', 'testuser', 'testpass', 'test') mysql.query("DROP TABLE IF EXISTS `insert_bm`") mysql.query("DROP TABLE IF EXISTS `insert_bm_coords`") mysql.query("CREATE TABLE `insert_bm_coords`( `id` int unsigned not null auto_increment, `x` int not null, `y` int not null, PRIMARY KEY (`id`) )") mysql.query("CREATE TABLE `insert_bm`( `id` int unsigned not null auto_increment, `text` varchar(255) not null, `count` int not null, `coords_id` int unsigned not null, PRIMARY KEY (`id`) )") # init mongodb mongo_db = Mongo::Connection.new.db("ololo_db") mongo_db.collection("beta").drop mongo = mongo_db.collection("beta") # do benchmarking Benchmark.bm {|x| x.report("mysql:") { cycle{|doc| mysql.query("INSERT insert_bm_coords(x,y) VALUES(#{doc["coords"]["x"]}, #{doc["coords"]["y"]})") mysql.query("INSERT insert_bm(text, count, coords_id) VALUES('#{doc["text"]}', #{doc["count"]}, #{mysql.insert_id()})") } } x.report("mongodb:") { cycle{|doc| mongo.insert(doc) } } }
Result:
10_000:
user system total real
mysql: 0.300000 0.150000 0.450000 ( 1.763819)
mongodb: 5.690000 0.680000 6.370000 ( 7.201129)
1_000_000:
user system total real
mysql: 30.960000 12.950000 43.910000 (179.318003)
mongodb:569.650000 18.410000 588.060000 (678.889538)
UPDATE: after installing C extension (`gem install mongo_ext`).
I'm confused. Can anybody explain it?
10_000:
user system total real
mysql: 0.280000 0.110000 0.390000 ( 1.679100)
mongodb: 3.110000 0.270000 3.380000 ( 4.089022)
1_000_000:
user system total real
mysql: 32.400000 13.030000 45.430000 (179.684186)
mongodb:326.150000 17.000000 343.150000 (423.631974)
Что-то тут не так, учитывая заявления о скорости MongoDB.
Кто-то может подтвердить или опровергнуть?
UPDATE: here is explanation: http://blog.knopkodav.ru/2009/11/mongo-mysql-ruby-and-php.html
пятница, 31 июля 2009 г.
Gentoo + rails + passenger + nginx
I installed ruby by compiling it myself (portage handled ruby doesn't quite do
it for me...). Then I installed the passenger gem 2.2.4. After installing
passenger gem went to the root passenger dir and ran "rake nginx" to get the
helperserver needed. Then I copied the nginx-0.7.61.ebuild and modified it to
include the use flag passenger. Then using the hint from the ebuild attached to
this bug got the full path for the nginx passenger module and put that into my
ebuild.
Then added the passenger use flag to /etc/portage/package.use for nginx and
emerged nginx 0.7.61 with passenger.
Added the config info to /etc/nginx.conf and I'm away everything works very
nicely :)
via http://bugs.gentoo.org/266446
вторник, 28 июля 2009 г.
Любителям длинных имён переменных
%username%, помни:
url -- полный путь к странице: http://localhost/blog/2009/07/28/kak-ya-upal-v-rechku
path -- только путь: blog/2009/07/28/kak-ya-upal-v-rechku
И не надо никаких названий переменных, типа: full_path, relative_path, etc.
среда, 22 июля 2009 г.
Converting Drupal tables to RoR from any to any database.
OK, OK, it's fairly not only for Drupal source databases :-)
STEP 1 - init databases connections
Create two new connections in database.yml file like this:
# DATABASE CONVERTING SPECIFIC
# old connection
old:
adapter: mysql
database: dbname
username: username
password: userpass
host: localhost
# new connection (may be like your development or production connection)
new:
adapter: postgresql
database: dbname
username: username
password: userpass
schema_order: development # for example
host: localhost
STEP 2 - write rake task
create convert.rake file in your lib/tasks rails application directory
1 namespace :db do
2 namespace :convert do
3 task :old2new => :environment do
4 print "OK, let's do it now!\n"; STDOUT.flush
5
6 # define universal model for old tables
7 class OldModel < ActiveRecord::Base
8 end
9
10 # demonic convertor
11 def convert(srctable, dstclass)
12 print "- converting class " + dstclass.to_s + "...\n"; STDOUT.flush
13
14 dstclass.establish_connection(:new)
15 dstclass.delete_all
16
17 OldModel.set_table_name(srctable)
18 OldModel.find(:all).each { |old|
19 new = dstclass.new
20 new = yield(old, new)
21 new.save(false)
22 }
23 end
24
25 # connect to old dying database
26 ActiveRecord::Base.establish_connection(:old)
27
28 # CONVERTING
29
30 # users
31 convert('rctc_users', User) {|old, new|
32 # prepare each field individually, yeah.
33 new.id = old.uid
34 new.login = old.name
35 new.email = old.mail
36 new.password = Digest::MD5.hexdigest(old.pass + SALT)
37 new
38 }
39
40 # convert your tables below like above
41 # ...
42
43 print "Wow! Processing complete!\n"
44 end
45 end
46 end
STEP 3 - RUN IT!
$ rake db:convert:old2new
суббота, 18 июля 2009 г.
Как починить man, less и другие проблемы tty в OpenVZ
сабж.
# rm /dev/tty
# mknod -m 666 /dev/tty c 5 0
пруфлинк: http://forum.openvz.org/index.php?t=msg&goto=34878&