понедельник, 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.


  1. #!/usr/bin/ruby



  2. require 'rubygems'

  3. require 'benchmark'



  4. require 'mongo'

  5. require 'mysql'



  6. # init benchmark cycle

  7. def cycle

  8. 10000.times{ |i|

  9. doc = {

  10. "text" => "i am any text and a little tail with me: #{i}",

  11. "count" => i,

  12. "coords" => {"x" => 203 + i, "y" => 102 + i}

  13. }



  14. yield doc

  15. }

  16. end



  17. # init mysql

  18. mysql = Mysql.new('localhost', 'testuser', 'testpass', 'test')

  19. mysql.query("DROP TABLE IF EXISTS `insert_bm`")

  20. mysql.query("DROP TABLE IF EXISTS `insert_bm_coords`")



  21. mysql.query("CREATE TABLE `insert_bm_coords`(

  22. `id` int unsigned not null auto_increment,

  23. `x` int not null,

  24. `y` int not null,

  25. PRIMARY KEY (`id`)

  26. )")



  27. mysql.query("CREATE TABLE `insert_bm`(

  28. `id` int unsigned not null auto_increment,

  29. `text` varchar(255) not null,

  30. `count` int not null,

  31. `coords_id` int unsigned not null,

  32. PRIMARY KEY (`id`)

  33. )")



  34. # init mongodb

  35. mongo_db = Mongo::Connection.new.db("ololo_db")

  36. mongo_db.collection("beta").drop

  37. mongo = mongo_db.collection("beta")



  38. # do benchmarking

  39. Benchmark.bm {|x|



  40. x.report("mysql:") {

  41. cycle{|doc|

  42. mysql.query("INSERT insert_bm_coords(x,y) VALUES(#{doc["coords"]["x"]}, #{doc["coords"]["y"]})")

  43. mysql.query("INSERT insert_bm(text, count, coords_id) VALUES('#{doc["text"]}', #{doc["count"]}, #{mysql.insert_id()})")

  44. }

  45. }



  46. x.report("mongodb:") {

  47. cycle{|doc|

  48. mongo.insert(doc)

  49. }

  50. }

  51. }





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`).


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)


I'm confused. Can anybody explain it?

Что-то тут не так, учитывая заявления о скорости 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&