pogocache-ruby 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md ADDED
@@ -0,0 +1,121 @@
1
+ # Pogocache::Ruby
2
+
3
+ Use [pogocache](https://github.com/tidwall/pogocache) as an in-memory store in Ruby.
4
+ This gem embeds pogocache as a C extension and provides the class `Pogocache::Cache`to interact with it.
5
+ The goal is to provide a faster, more lightweight alternative to `ActiveSupport::Cache::MemoryStore.
6
+ The state of this project is pretty much pre alfa but functional.
7
+
8
+ ## Features
9
+
10
+ - Fast caching operations
11
+ - Low memory footprint
12
+ - Arbitrary objects as keys and values
13
+ - Linux and MacOS support
14
+
15
+ ## Threading
16
+
17
+ This gem relies on the GVL when used in a multi-threaded context.
18
+ It does not free the lock before any operation.
19
+
20
+ ## Usage
21
+
22
+ ```
23
+ [...]
24
+ ```
25
+
26
+ ## Todos
27
+
28
+ - [ ] add interface to be used as a rails cache
29
+ - [ ] improve interface
30
+
31
+ ## Benchmark
32
+
33
+ ```ruby
34
+ require 'pogocache-ruby'
35
+ require 'active_support'
36
+ require 'active_support/cache'
37
+ require 'benchmark'
38
+ require 'benchmark/memory'
39
+
40
+ memory_store = ActiveSupport::Cache::MemoryStore.new
41
+ pogocache_store = Pogocache::Cache.new(usecas: true, nosixpack: true)
42
+ pogocache_batch_store = Pogocache::Cache.new
43
+
44
+ N = 100_000
45
+
46
+ puts "Benchmarking WRITE performance (#{N} keys)..."
47
+ Benchmark.bm(20) do |x|
48
+ x.report("MemoryStore write:") do
49
+ N.times { |i| memory_store.write("key#{i}", { number: i, value: nil}) }
50
+ end
51
+
52
+ x.report("Pogocache write:") do
53
+ N.times { |i| pogocache_store.set("key#{i}", { number: i, value: nil}) }
54
+ end
55
+ end
56
+
57
+ puts "\nBenchmarking READ performance (#{N} keys)..."
58
+ Benchmark.bm(20) do |x|
59
+ x.report("MemoryStore read:") do
60
+ N.times { |i| memory_store.read("key#{i}") }
61
+ end
62
+
63
+ x.report("Pogocache read:") do
64
+ N.times { |i| pogocache_store.get("key#{i}") }
65
+ end
66
+ end
67
+
68
+ puts "Benchmarking WRITE performance (#{N} keys)..."
69
+ Benchmark.memory do |x|
70
+ x.report("MemoryStore write:") do
71
+ N.times { |i| memory_store.write("key#{i}", { number: i, value: nil}) }
72
+ end
73
+
74
+ x.report("Pogocache write:") do
75
+ N.times { |i| pogocache_store.set("key#{i}", { number: i, value: nil}) }
76
+ end
77
+ end
78
+
79
+ puts "\nBenchmarking READ performance (#{N} keys)..."
80
+ Benchmark.memory do |x|
81
+ x.report("MemoryStore read:") do
82
+ N.times { |i| memory_store.read("key#{i}") }
83
+ end
84
+
85
+ x.report("Pogocache read:") do
86
+ N.times { |i| pogocache_store.get("key#{i}") }
87
+ end
88
+ end
89
+
90
+ ```
91
+
92
+ ```
93
+ Benchmarking WRITE performance (100000 keys)...
94
+ user system total real
95
+ MemoryStore write: 0.663600 0.015039 0.678639 ( 0.678977)
96
+ Pogocache write: 0.193228 0.012096 0.205324 ( 0.205405)
97
+
98
+ Benchmarking READ performance (100000 keys)...
99
+ user system total real
100
+ MemoryStore read: 0.456161 0.003899 0.460060 ( 0.460138)
101
+ Pogocache read: 0.205501 0.000000 0.205501 ( 0.205520)
102
+
103
+ Benchmarking WRITE performance (100000 keys)...
104
+ Calculating -------------------------------------
105
+ MemoryStore write: 239.200M memsize ( 15.200M retained)
106
+ 2.000M objects ( 200.000k retained)
107
+ 50.000 strings ( 50.000 retained)
108
+ Pogocache write: 54.396M memsize ( 0.000 retained)
109
+ 599.990k objects ( 0.000 retained)
110
+ 50.000 strings ( 0.000 retained)
111
+
112
+ Benchmarking READ performance (100000 keys)...
113
+ Calculating -------------------------------------
114
+ MemoryStore read: 116.000M memsize ( 0.000 retained)
115
+ 1.200M objects ( 0.000 retained)
116
+ 50.000 strings ( 0.000 retained)
117
+ Pogocache read: 71.192M memsize ( 0.000 retained)
118
+ 899.990k objects ( 0.000 retained)
119
+ 50.000 strings ( 0.000 retained)
120
+
121
+ ```
data/Rakefile ADDED
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+ require "standard/rake"
6
+ require "yard"
7
+ require "rake/extensiontask"
8
+
9
+ RSpec::Core::RakeTask.new(:spec)
10
+ YARD::Rake::YardocTask.new
11
+
12
+ task default: %i[spec standard]
13
+
14
+ Rake::ExtensionTask.new("pogocache_ruby")
15
+
16
+ namespace :pogocache do
17
+ desc "Download pogocache library"
18
+ task :build_lib do
19
+ require_relative "lib/pogocache-ruby/platform"
20
+
21
+ ext_dir = File.join(__dir__, "ext", "pogocache")
22
+ FileUtils.mkdir_p(ext_dir)
23
+
24
+ Dir.chdir(ext_dir) do
25
+ puts "Downloading pogocache source..."
26
+ system("curl -L https://raw.githubusercontent.com/tidwall/pogocache/refs/heads/main/src/pogocache.c -o pogocache.c")
27
+ system("curl -L https://raw.githubusercontent.com/tidwall/pogocache/refs/heads/main/src/pogocache.h -o pogocache.h")
28
+ end
29
+ end
30
+ end
31
+
32
+ # Build library before running tests
33
+ task spec: "compile"
@@ -0,0 +1,4 @@
1
+ require "mkmf"
2
+
3
+ have_library("pthread")
4
+ create_makefile("pogocache_ruby/pogocache_ruby")