Sha256: d92de6690deeeb72efe605160e0ad548b4cb713a109b4d65401275998e0b100d
Contents?: true
Size: 1.06 KB
Versions: 11
Compression:
Stored size: 1.06 KB
Contents
require 'bundler/setup' require 'groovy' Groovy.open('./db/products') class Product include Groovy::Model schema do |t| t.string :name t.integer :price t.boolean :published t.timestamps end scope :by_price, -> { puts self.inspect; sort_by(price: :asc) } scope :named, -> (name) { puts self.inspect; where(name: name) if name } end def populate 5_000.times do |i| puts "Creating product #{i}" if i % 1000 == 0 Product.create!(name: "A product with index #{i}", published: true, price: 10000 + i % 10) end end populate if Product.count == 0 # 50_000 products: 50M # 100_000 products: 50M # 500_000 products: 62M module MemInfo KERNEL_PAGE_SIZE = `getconf PAGESIZE`.chomp.to_i rescue 4096 STATM_PATH = "/proc/#{Process.pid}/statm" STATM_FOUND = File.exist?(STATM_PATH) def self.rss STATM_FOUND ? (File.read(STATM_PATH).split(' ')[1].to_i * KERNEL_PAGE_SIZE) / 1024 : 0 end end puts MemInfo.rss prices = Product.all.map { |x| x.price } puts prices.inspect puts MemInfo.rss
Version data entries
11 entries across 11 versions & 1 rubygems