Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Compare performance of various implementations on up / down voting problem

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 results
Octocat-spinner-32 solutions
Octocat-spinner-32 .rvmrc
Octocat-spinner-32 Gemfile
Octocat-spinner-32 Gemfile.lock
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 TODO
Octocat-spinner-32 benchmark.rb
Octocat-spinner-32 config.rb
Octocat-spinner-32 run.sh
README.rdoc

Limitation

Current benchmark code run a for loop to create / destroy votes sequently. It does not utilize database 100%.

Results are validated after each vote / unvote and it takes some time too.

Solutions

  • ActiveRecordSolution: Use votes table, store counters (votes_counts, up_votes_count, down_votes_count) and votes_point in posts

  • NaiveMongoidSolution: Equivalent to ActiveRecordSolution (use votes collection …)

  • VoteableMongoidSolution: Use github.com/vinova/voteable_mongo gem

  • VoteableMongoMapperSolution: Use github.com/vinova/voteable_mongo gem

Benchmark Results

Settings

Linode 768MB RAM
Ubuntu 10.04 Server 32-bit
MySQL 5.1.41 Community Server
MongoDB 1.8.1
Ruby 1.9.2p180
1,000,000 votes (see results/1_000_000.txt)

Without additional indexing

Note: skip_additional_indexes mean skip creating indexes that don't speed up voting and unvoting processes (e.g. counters, votes_point)

ActiveRecordSolution

Creating 1,000,000 votes ...
      user     system      total        real
3659.920000 222.440000 3882.360000 (5296.368667)

Unvoting 1,000,000 votes ...
      user     system      total        real
2749.690000 220.430000 2970.120000 (4233.962804)

NaiveMongoidSolution

Creating 1,000,000 votes ...
      user     system      total        real
2142.600000 200.410000 2343.010000 (2616.700013)

Unvoting 1,000,000 votes ...
      user     system      total        real
1809.470000 194.090000 2003.560000 (2257.708869)

VoteableMongoidSolution

Creating 1,000,000 votes ...
      user     system      total        real
884.970000  52.470000 937.440000 (1516.276592)

Unvoting 1,000,000 votes ...
      user     system      total        real
876.690000  52.800000 929.490000 (1426.762185)

VoteableMongoMapperSolution

Creating 1,000,000 votes ...
      user     system      total        real
973.710000  53.920000 1027.630000 (1601.420442)

Unvoting 1,000,000 votes ...
      user     system      total        real
955.710000  51.900000 1007.610000 (1500.587057)

With additional indexing

ActiveRecordSolution

Creating 1,000,000 votes ...
      user     system      total        real
3759.180000 225.800000 3984.980000 (5298.808792)

Unvoting 1,000,000 votes ...
      user     system      total        real
2784.350000 222.950000 3007.300000 (4311.266611)

NaiveMongoidSolution

Creating 1,000,000 votes ...
      user     system      total        real
2005.860000 191.970000 2197.830000 (2496.578666)

Unvoting 1,000,000 votes ...
      user     system      total        real
1721.470000 186.650000 1908.120000 (2159.386849)

VoteableMongoidSolution

Creating 1,000,000 votes ...
      user     system      total        real
895.680000  48.510000 944.190000 (1938.072613)

Unvoting 1,000,000 votes ...
      user     system      total        real
880.260000  53.610000 933.870000 (1652.896735)

VoteableMongoMapperSolution

Creating 1,000,000 votes ...
      user     system      total        real
1007.940000  49.920000 1057.860000 (2068.367740)

Unvoting 1,000,000 votes ...
      user     system      total        real
967.250000  54.300000 1021.550000 (1752.818840)
Something went wrong with that request. Please try again.