jashmenn-dalli 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source :rubygems
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem 'simplecov'
7
+ end
@@ -0,0 +1,169 @@
1
+ Dalli Changelog
2
+ =====================
3
+
4
+ 1.0.3
5
+ =======
6
+
7
+ - Better handling of application marshalling errors
8
+ - Work around jruby IO#sysread compatibility issue
9
+
10
+
11
+ 1.0.2
12
+ =======
13
+
14
+ - Allow browser session cookies (blindsey)
15
+ - Compatibility fixes (mwynholds)
16
+ - Add backwards compatibility module for memcache-client, require 'dalli/memcache-client'. It makes
17
+ Dalli more compatible with memcache-client and prints out a warning any time you do something that
18
+ is no longer supported so you can fix your code.
19
+
20
+ 1.0.1
21
+ =======
22
+
23
+ - Explicitly handle application marshalling bugs, GH-56
24
+ - Add support for username/password as options, to allow multiple bucket access
25
+ from the same Ruby process, GH-52
26
+ - Add support for >1MB values with :value_max_bytes option, GH-54 (r-stu31)
27
+ - Add support for default TTL, :expires_in, in Rails 2.3. (Steven Novotny)
28
+ config.cache_store = :dalli_store, 'localhost:11211', {:expires_in => 4.hours}
29
+
30
+
31
+ 1.0.0
32
+ =======
33
+
34
+ Welcome gucki as a Dalli committer!
35
+
36
+ - Fix network and namespace issues in get_multi (gucki)
37
+ - Better handling of unmarshalling errors (mperham)
38
+
39
+ 0.11.2
40
+ =======
41
+
42
+ - Major reworking of socket error and failover handling (gucki)
43
+ - Add basic JRuby support (mperham)
44
+
45
+ 0.11.1
46
+ ======
47
+
48
+ - Minor fixes, doc updates.
49
+ - Add optional support for kgio sockets, gives a 10-15% performance boost.
50
+
51
+ 0.11.0
52
+ ======
53
+
54
+ Warning: this release changes how Dalli marshals data. I do not guarantee compatibility until 1.0 but I will increment the minor version every time a release breaks compatibility until 1.0.
55
+
56
+ IT IS HIGHLY RECOMMENDED YOU FLUSH YOUR CACHE BEFORE UPGRADING.
57
+
58
+ - multi() now works reentrantly.
59
+ - Added new Dalli::Client option for default TTLs, :expires_in, defaults to 0 (aka forever).
60
+ - Added new Dalli::Client option, :compression, to enable auto-compression of values.
61
+ - Refactor how Dalli stores data on the server. Values are now tagged
62
+ as "marshalled" or "compressed" so they can be automatically deserialized
63
+ without the client having to know how they were stored.
64
+
65
+ 0.10.1
66
+ ======
67
+
68
+ - Prefer server config from environment, fixes Heroku session store issues (thanks JoshMcKin)
69
+ - Better handling of non-ASCII values (size -> bytesize)
70
+ - Assert that keys are ASCII only
71
+
72
+ 0.10.0
73
+ ======
74
+
75
+ Warning: this release changed how Rails marshals data with Dalli. Unfortunately previous versions double marshalled values. It is possible that data stored with previous versions of Dalli will not work with this version.
76
+
77
+ IT IS HIGHLY RECOMMENDED YOU FLUSH YOUR CACHE BEFORE UPGRADING.
78
+
79
+ - Rework how the Rails cache store does value marshalling.
80
+ - Rework old server version detection to avoid a socket read hang.
81
+ - Refactor the Rails 2.3 :dalli\_store to be closer to :mem\_cache\_store.
82
+ - Better documentation for session store config (plukevdh)
83
+
84
+ 0.9.10
85
+ ----
86
+
87
+ - Better server retry logic (next2you)
88
+ - Rails 3.1 compatibility (gucki)
89
+
90
+
91
+ 0.9.9
92
+ ----
93
+
94
+ - Add support for *_multi operations for add, set, replace and delete. This implements
95
+ pipelined network operations; Dalli disables network replies so we're not limited by
96
+ latency, allowing for much higher throughput.
97
+
98
+ dc = Dalli::Client.new
99
+ dc.multi do
100
+ dc.set 'a', 1
101
+ dc.set 'b', 2
102
+ dc.set 'c', 3
103
+ dc.delete 'd'
104
+ end
105
+ - Minor fix to set the continuum sorted by value (kangster)
106
+ - Implement session store with Rails 2.3. Update docs.
107
+
108
+ 0.9.8
109
+ -----
110
+
111
+ - Implement namespace support
112
+ - Misc fixes
113
+
114
+
115
+ 0.9.7
116
+ -----
117
+
118
+ - Small fix for NewRelic integration.
119
+ - Detect and fail on older memcached servers (pre-1.4).
120
+
121
+ 0.9.6
122
+ -----
123
+
124
+ - Patches for Rails 3.0.1 integration.
125
+
126
+ 0.9.5
127
+ -----
128
+
129
+ - Major design change - raw support is back to maximize compatibility with Rails
130
+ and the increment/decrement operations. You can now pass :raw => true to most methods
131
+ to bypass (un)marshalling.
132
+ - Support symbols as keys (ddollar)
133
+ - Rails 2.3 bug fixes
134
+
135
+
136
+ 0.9.4
137
+ -----
138
+
139
+ - Dalli support now in rack-bug (http://github.com/brynary/rack-bug), give it a try!
140
+ - Namespace support for Rails 2.3 (bpardee)
141
+ - Bug fixes
142
+
143
+
144
+ 0.9.3
145
+ -----
146
+
147
+ - Rails 2.3 support (beanieboi)
148
+ - Rails SessionStore support
149
+ - Passenger integration
150
+ - memcache-client upgrade docs, see Upgrade.md
151
+
152
+
153
+ 0.9.2
154
+ ----
155
+
156
+ - Verify proper operation in Heroku.
157
+
158
+
159
+ 0.9.1
160
+ ----
161
+
162
+ - Add fetch and cas operations (mperham)
163
+ - Add incr and decr operations (mperham)
164
+ - Initial support for SASL authentication via the MEMCACHE_{USERNAME,PASSWORD} environment variables, needed for Heroku (mperham)
165
+
166
+ 0.9.0
167
+ -----
168
+
169
+ - Initial gem release.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Mike Perham
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,77 @@
1
+ Performance
2
+ ====================
3
+
4
+ Caching is all about performance, so I carefully track Dalli performance to ensure no regressions.
5
+ Times are from a Unibody MBP 2.4Ghz Core i5 running Snow Leopard.
6
+
7
+ You can optionally use kgio to give Dalli a small, 10-20% performance boost: gem install kgio.
8
+
9
+ *memcache-client*:
10
+
11
+ Testing 1.8.5 with ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-darwin10.6.0]
12
+ user system total real
13
+ set:plain:memcache 2.070000 0.340000 2.410000 ( 2.611709)
14
+ set:ruby:memcache 1.990000 0.330000 2.320000 ( 2.869653)
15
+ get:plain:memcache 2.290000 0.360000 2.650000 ( 2.926425)
16
+ get:ruby:memcache 2.360000 0.350000 2.710000 ( 2.951604)
17
+ multiget:ruby:memcache 1.050000 0.120000 1.170000 ( 1.285787)
18
+ missing:ruby:memcache 1.990000 0.330000 2.320000 ( 2.567641)
19
+ mixed:ruby:memcache 4.390000 0.670000 5.060000 ( 5.721000)
20
+ incr:ruby:memcache 0.700000 0.120000 0.820000 ( 0.842896)
21
+
22
+ *libmemcached*:
23
+
24
+ Testing 1.1.2 with ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-darwin10.6.0]
25
+ user system total real
26
+ set:plain:libm 0.120000 0.220000 0.340000 ( 0.847521)
27
+ setq:plain:libm 0.030000 0.000000 0.030000 ( 0.126944)
28
+ set:ruby:libm 0.220000 0.250000 0.470000 ( 1.102789)
29
+ get:plain:libm 0.140000 0.230000 0.370000 ( 0.813998)
30
+ get:ruby:libm 0.210000 0.240000 0.450000 ( 1.025994)
31
+ multiget:ruby:libm 0.100000 0.080000 0.180000 ( 0.322217)
32
+ missing:ruby:libm 0.250000 0.240000 0.490000 ( 1.049972)
33
+ mixed:ruby:libm 0.400000 0.410000 0.810000 ( 2.172349)
34
+ mixedq:ruby:libm 0.410000 0.360000 0.770000 ( 1.516718)
35
+ incr:ruby:libm 0.080000 0.340000 0.420000 ( 1.685931)
36
+
37
+ *dalli*:
38
+
39
+ Using kgio socket IO
40
+ Testing 1.0.2 with ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-darwin10.6.0]
41
+ user system total real
42
+ set:plain:dalli 0.850000 0.320000 1.170000 ( 1.691393)
43
+ setq:plain:dalli 0.500000 0.130000 0.630000 ( 0.651227)
44
+ set:ruby:dalli 0.900000 0.330000 1.230000 ( 1.865228)
45
+ get:plain:dalli 0.990000 0.390000 1.380000 ( 1.929994)
46
+ get:ruby:dalli 0.950000 0.370000 1.320000 ( 1.844251)
47
+ multiget:ruby:dalli 0.790000 0.300000 1.090000 ( 1.227073)
48
+ missing:ruby:dalli 0.810000 0.370000 1.180000 ( 1.627039)
49
+ mixed:ruby:dalli 1.850000 0.710000 2.560000 ( 3.555032)
50
+ mixedq:ruby:dalli 1.840000 0.610000 2.450000 ( 2.945982)
51
+ incr:ruby:dalli 0.310000 0.120000 0.430000 ( 0.616465)
52
+
53
+ Testing 1.0.2 with rubinius 1.3.0dev (1.8.7 382e813f xxxx-xx-xx JI) [x86_64-apple-darwin10.6.0]
54
+ user system total real
55
+ set:plain:dalli 2.800581 0.329360 3.129941 ( 5.186546)
56
+ setq:plain:dalli 1.064253 0.138044 1.202297 ( 1.280355)
57
+ set:ruby:dalli 2.220885 0.262619 2.483504 ( 2.778118)
58
+ get:plain:dalli 2.291344 0.280490 2.571834 ( 2.948004)
59
+ get:ruby:dalli 2.148900 0.274477 2.423377 ( 2.425808)
60
+ multiget:ruby:dalli 1.724193 0.249145 1.973338 ( 2.158673)
61
+ missing:ruby:dalli 1.881502 0.272610 2.154112 ( 2.208384)
62
+ mixed:ruby:dalli 4.292620 0.533768 4.826388 ( 4.830238)
63
+ mixedq:ruby:dalli 4.076032 0.501442 4.577474 ( 4.583800)
64
+ incr:ruby:dalli 0.691467 0.091475 0.782942 ( 0.931674)
65
+
66
+ Testing 1.0.2 with rubinius 1.2.0 (1.8.7 release 2010-12-21 JI) [x86_64-apple-darwin10.6.0]
67
+ user system total real
68
+ set:plain:dalli 6.586927 0.331545 6.918472 ( 4.628652)
69
+ setq:plain:dalli 0.930905 0.129008 1.059913 ( 1.016105)
70
+ set:ruby:dalli 2.702486 0.283004 2.985490 ( 2.690442)
71
+ get:plain:dalli 2.740202 0.291353 3.031555 ( 2.722746)
72
+ get:ruby:dalli 1.979379 0.282986 2.262365 ( 2.264118)
73
+ multiget:ruby:dalli 1.887086 0.249799 2.136885 ( 1.803230)
74
+ missing:ruby:dalli 1.882662 0.278019 2.160681 ( 2.113429)
75
+ mixed:ruby:dalli 3.969242 0.553361 4.522603 ( 4.524504)
76
+ mixedq:ruby:dalli 3.520755 0.475669 3.996424 ( 3.997405)
77
+ incr:ruby:dalli 0.849998 0.094012 0.944010 ( 0.884001)
@@ -0,0 +1,177 @@
1
+ Dalli
2
+ =========
3
+
4
+ Dalli is a high performance pure Ruby client for accessing memcached servers. It works with memcached 1.4+ only as it uses the newer binary protocol. It should be considered a replacement for the memcache-client gem. The API tries to be mostly compatible with memcache-client with the goal being to make it a drop-in replacement for Rails.
5
+
6
+ The name is a variant of Salvador Dali for his famous painting [The Persistence of Memory](http://en.wikipedia.org/wiki/The_Persistence_of_Memory).
7
+
8
+ ![Persistence of Memory](http://www.virtualdali.com/assets/paintings/31PersistenceOfMemory.jpg)
9
+
10
+ Dalli's development is sponsored by [Membase](http://www.membase.com/). Many thanks to them!
11
+
12
+
13
+ Design
14
+ ------------
15
+
16
+ I decided to write Dalli after maintaining memcache-client for the last two years for a few specific reasons:
17
+
18
+ 0. The code is mostly old and gross. The bulk of the code is a single 1000 line .rb file.
19
+ 1. It has a lot of options that are infrequently used which complicate the codebase.
20
+ 2. The implementation has no single point to attach monitoring hooks.
21
+ 3. Uses the old text protocol, which hurts raw performance.
22
+
23
+ So a few notes. Dalli:
24
+
25
+ 0. uses the exact same algorithm to choose a server so existing memcached clusters with TBs of data will work identically to memcache-client.
26
+ 1. is approximately 20% faster than memcache-client (which itself was heavily optimized) in Ruby 1.9.2.
27
+ 2. contains explicit "chokepoint" methods which handle all requests; these can be hooked into by monitoring tools (NewRelic, Rack::Bug, etc) to track memcached usage.
28
+ 3. comes with hooks to replace memcache-client in Rails.
29
+ 4. is approx 700 lines of Ruby. memcache-client is approx 1250 lines.
30
+ 5. supports SASL for use in managed environments, e.g. Heroku.
31
+ 6. provides proper failover with recovery and adjustable timeouts
32
+ 7. has a backwards-compatibility mode for people migrating from memcache-client (see Upgrade.md).
33
+
34
+
35
+ Installation and Usage
36
+ ------------------------
37
+
38
+ Remember, Dalli **requires** memcached 1.4+. You can check the version with `memcached -h`.
39
+
40
+ gem install dalli
41
+
42
+ require 'dalli'
43
+ dc = Dalli::Client.new('localhost:11211')
44
+ dc.set('abc', 123)
45
+ value = dc.get('abc')
46
+
47
+ The test suite requires memcached 1.4.3+ with SASL enabled (brew install memcached --enable-sasl ; mv /usr/bin/memcache /usr/bin/memcached.old). Currently only supports the PLAIN mechanism.
48
+
49
+ Dalli has no runtime dependencies and never will. You can optionally install the 'kgio' gem to
50
+ give Dalli a 10-20% performance boost.
51
+
52
+
53
+ Usage with Rails 3.0
54
+ ---------------------------
55
+
56
+ In your Gemfile:
57
+
58
+ gem 'dalli'
59
+
60
+ In `config/environments/production.rb`:
61
+
62
+ config.cache_store = :dalli_store
63
+
64
+ A more comprehensive example (note that we are setting a reasonable default for maximum cache entry lifetime (one day), enabling compression for large values, and namespacing all entries for this rails app. Remove the namespace if you have multiple apps which share cached values):
65
+
66
+ config.cache_store = :dalli_store, 'cache-1.example.com', 'cache-2.example.com',
67
+ { :namespace => NAME_OF_RAILS_APP, :expires_in => 1.day, :compress => true, :compress_threshold => 64*1024 }
68
+
69
+ To use Dalli for Rails session storage, in `config/initializers/session_store.rb`:
70
+
71
+ require 'action_dispatch/middleware/session/dalli_store'
72
+ Rails.application.config.session_store :dalli_store, :memcache_server => ['host1', 'host2'], :namespace => 'sessions', :key => '_foundation_session', :expire_after => 30.minutes
73
+
74
+
75
+ Usage with Rails 2.3.x
76
+ ----------------------------
77
+
78
+ In `config/environment.rb`:
79
+
80
+ config.gem 'dalli'
81
+
82
+ In `config/environments/production.rb`:
83
+
84
+ # Object cache
85
+ require 'active_support/cache/dalli_store23'
86
+ config.cache_store = :dalli_store
87
+
88
+ In `config/initializers/session_store.rb`:
89
+
90
+ # Session cache
91
+ ActionController::Base.session = {
92
+ :namespace => 'sessions',
93
+ :expire_after => 20.minutes.to_i,
94
+ :memcache_server => ['server-1:11211', 'server-2:11211'],
95
+ :key => ...,
96
+ :secret => ...
97
+ }
98
+
99
+ require 'action_controller/session/dalli_store'
100
+ ActionController::Base.session_store = :dalli_store
101
+
102
+
103
+ Usage with Passenger
104
+ ------------------------
105
+
106
+ Put this at the bottom of `config/environment.rb`:
107
+
108
+ if defined?(PhusionPassenger)
109
+ PhusionPassenger.on_event(:starting_worker_process) do |forked|
110
+ # Only works with DalliStore
111
+ Rails.cache.reset if forked
112
+ end
113
+ end
114
+
115
+
116
+ Configuration
117
+ ------------------------
118
+ Dalli::Client accepts the following options. All times are in seconds.
119
+
120
+ **expires_in**: Global default for key TTL. No default.
121
+
122
+ **failover**: Boolean, if true Dalli will failover to another server if the main server for a key is down.
123
+
124
+ **compression**: Boolean, if true Dalli will gzip-compress values larger than 1K.
125
+
126
+ **socket_timeout**: Timeout for all socket operations (connect, read, write). Default is 0.5.
127
+
128
+ **socket_max_failures**: When a socket operation fails after socket_timeout, the same operation is retried. This is to not immediately mark a server down when there's a very slight network problem. Default is 2.
129
+
130
+ **socket_failure_delay**: Before retrying a socket operation, the process sleeps for this amount of time. Default is 0.01. Set to nil for no delay.
131
+
132
+ **down_retry_delay**: When a server has been marked down due to many failures, the server will be checked again for being alive only after this amount of time. Don't set this value to low, otherwise each request which tries the failed server might hang for the maximum **socket_timeout**. Default is 1 second.
133
+
134
+ **value_max_bytes**: The maximum size of a value in memcached. Defaults to 1MB, this can be increased with memcached's -I parameter. You must also configure Dalli to allow the larger size here.
135
+
136
+ **username**: The username to use for authenticating this client instance against a SASL-enabled memcached server. Heroku users should not need to use this normally.
137
+
138
+ **password**: The password to use for authenticating this client instance against a SASL-enabled memcached server. Heroku users should not need to use this normally.
139
+
140
+ Features and Changes
141
+ ------------------------
142
+
143
+ Dalli is **NOT** 100% API compatible with memcache-client. If you have code which uses the MemCache API directly, it will likely need small tweaks. Method parameters and return values changed slightly. See Upgrade.md for more detail.
144
+
145
+ By default, Dalli is thread-safe. Disable thread-safety at your own peril.
146
+
147
+ Note that Dalli does not require ActiveSupport or Rails. You can safely use it in your own Ruby projects.
148
+
149
+
150
+ Helping Out
151
+ -------------
152
+
153
+ If you have a fix you wish to provide, please fork the code, fix in your local project and then send a pull request on github. Please ensure that you include a test which verifies your fix and update History.md with a one sentence description of your fix so you get credit as a contributor.
154
+
155
+
156
+ Thanks
157
+ ------------
158
+
159
+ Eric Wong - for help using his [kgio](http://unicorn.bogomips.org/kgio/index.html) library.
160
+
161
+ Brian Mitchell - for his remix-stash project which was helpful when implementing and testing the binary protocol support.
162
+
163
+ [Membase](http://membase.com) - for their project sponsorship
164
+
165
+ [Bootspring](http://bootspring.com) is my Ruby and Rails consulting company. We specialize in Ruby infrastructure, performance and scalability tuning for Rails applications. If you need help, please [contact us](mailto:info@bootspring.com) today.
166
+
167
+
168
+ Author
169
+ ----------
170
+
171
+ Mike Perham, mperham@gmail.com, [mikeperham.com](http://mikeperham.com), [@mperham](http://twitter.com/mperham) If you like and use this project, please give me a recommendation at [WWR](http://workingwithrails.com/person/10797-mike-perham). Happy caching!
172
+
173
+
174
+ Copyright
175
+ -----------
176
+
177
+ Copyright (c) 2010 Mike Perham. See LICENSE for details.