Commit Graph

49 Commits

Author SHA1 Message Date
Takuya ASADA
991b77863d Use namespace on timer_set to prevent conflict with OSv's timer_set
Since we have same header on OSv too, we need to prevent conflict.

Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
2015-04-19 10:33:36 +03:00
Tomasz Grabiec
83963b23d3 Replace rescue() usages with then_wrapped()
They are pretty much the same. This change removes rescue().
2015-03-04 17:34:59 +01:00
Raphael S. Carvalho
89ec1f8f6a slab: Add reclaimer functionality
Basic explanation of the reclaimer algorithm:
- Each slab page has a descriptor containing information about it, such as
refcnt, vector of free objects, link into LRU, etc.
- The LRU list will only contain slab pages which items are unused, so as
to make the reclaiming process faster and easier. Maintaining the LRU of slab
pages has a performance penalty of ~1.3%. Shlomi suggested an approach where
LRU would no longer exist and timestamp would be used instead to keep track of
recency. Reclaimer would then iterate through all slab pages checking for an
unused slab page with the lowest timestamp.
- Reclaimer will get the least-recently-used slab page from the LRU list,
do all the management stuff required, and iterate through the page erasing any
of the items there contained. Once reclaimer was called, it's likely that slab
memory usage is calibrated, thus slab pages shouldn't be allocated anymore.
- Reclaimer is enabled by default but can be disabled by specifying the slab
size using the application parameter --max-slab-size.

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2015-03-04 17:40:58 +02:00
Raphael S. Carvalho
aa6d850228 memcached: Integrate slab allocator
* Item structure was changed to work with slab, where its last field
is used to access key, value, and ascii prefix, respectively.
* Item structured was worked to have a smaller footprint. It was
reduced from 104 bytes to 72 bytes.
* Reclaimer was temporarily disabled.
* Global LRU was removed from the cache. Now LRU eviction is done
on a per-slab-class basis, whenever the slab allocator runs out of
slab pages.
* Fragmentation issue is naturally solved with the slab algorithm,
where slab classes have chunks of the same size.
2015-02-25 19:29:36 -03:00
Raphael S. Carvalho
66117b2697 memcached: Expiry should be stored as a 32-bit value
Expiration time is a 32-bit value as specified by memcached protocol.
Thus, no need to store it as a 64-bit value. When the value is needed,
convert it to the target type. Change intended to save space from
item structure.
In addition, there is no need to insert an entry into _alive when
expiration time is zero, meaning item will never expire.

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2015-02-25 19:29:36 -03:00
Raphael S. Carvalho
b461b42ce8 memcached: Revert flashcached
Flashcached integration was done relying on certain similarities between
flashcached and memcached. Old assumptions no longer hold.
As a result, the current code is terrible to integrate the slab allocator
into it, while keeping flashcached alive.
This patch reverts flashcached from memcached. It should be re-integrated
in the future, but definitely in a better way.
2015-02-25 19:29:36 -03:00
Avi Kivity
7f8d88371a Add LICENSE, NOTICE, and copyright headers to all source files.
The two files imported from the OSv project retain their original licenses.
2015-02-19 16:52:34 +02:00
Raphael S. Carvalho
20151b7b2a memcached: capture port by value
Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2015-02-12 10:00:37 +02:00
Raphael S. Carvalho
c725014614 memcached: add option to listen on a different port
useful when testing multiple memcached servers.

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2015-02-10 19:27:43 +02:00
Raphael S. Carvalho
2195f77879 memcached: stats: rename evicted to evictions
Change for compliance with stock memcached.

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2015-02-07 19:57:19 +02:00
Gleb Natapov
7a92efe8d1 core: add local engine accessor function
Do not use thread local engine variable directly, but use accessor
instead.
2015-01-27 14:46:49 +02:00
Gleb Natapov
57bcec15c7 memcached: flush cache during destruction.
Also add assert to item's cancel() function. It cannot be called after
cache is flushed.

Reviewed-by: Tomasz Grabiec <tgrabiec@gmail.com>
2015-01-15 18:25:30 +02:00
Takuya ASADA
e1552ad3b6 core: rename smp.hh to distributed.hh
Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
2015-01-14 11:16:09 +02:00
Avi Kivity
f2e25b8442 Merge branch 'shared_ptr'
Split shared_ptr into a traditional polymorphic shared_ptr implementation,
and a lighter-weight, non polymorphic lw_shared_ptr.
2015-01-05 11:29:35 +02:00
Avi Kivity
87f63f7b90 shared_ptr: rename to lw_shared_ptr (for light-weight)
The current shared_ptr implementation is efficient, but does not support
polymorphic types.

Rename it in order to make room for a polymorphic shared_ptr.
2015-01-04 22:38:49 +02:00
Raphael S. Carvalho
48019c2df2 memcache: fix cache::item_footprint()
size of the sstring _ascii_prefix should also be added when computing
item footprint. Without this change, reclaimer would end up evicting
more than needed.

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2014-12-28 10:24:09 +02:00
Gleb Natapov
466acedcb2 timer: cancel all timers during reactor destruction
If a timer is not canceled it will try to cancel itself during
destruction which may happen after engine is already destroyed.
2014-12-25 09:14:42 +02:00
Asias He
0242d402b7 timer: Drop Clock template parameter in time_set 2014-12-15 19:39:33 +08:00
Asias He
62fff15e54 timer: Make timer a template 2014-12-15 19:39:33 +08:00
Tomasz Grabiec
8bfca6f740 memcached: convert 'get' to use zero-copy send. 2014-12-04 13:51:35 +01:00
Tomasz Grabiec
c4335c49f6 core: convert output APIs to work on packets
This way zero-copy supporting code can put data directly to packet
object and pass it through all layers efficiently.
2014-12-04 13:51:26 +01:00
Tomasz Grabiec
b6cb2b7477 memcached: add missing return 2014-12-04 13:37:35 +01:00
Tomasz Grabiec
e4583699fd memcached: make sure datagrams are below the size limit 2014-12-04 13:37:35 +01:00
Avi Kivity
6b5973af70 app-template: don't alias boost::program_options as bpo in a header file
We only have one global namespace, let's work together to keep it free
of pollution.
2014-12-01 17:56:34 +02:00
Raphael S. Carvalho
0653a9f3f7 flashcache: fix _total_mem_disk accounting when erasing mem-disk items
Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2014-12-01 10:30:23 -02:00
Raphael S. Carvalho
9de9f34423 flashcache: fix erase on disk-based items
Fixed by adding missing break statement.

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2014-12-01 10:28:42 -02:00
Avi Kivity
9c7fc9d5d1 memcache: massage init capture to satisfy clang 2014-11-26 14:56:18 +02:00
Avi Kivity
05e8ee5e0c memcache: remove unneeded use of variable length array
Noticed by clang.
2014-11-26 14:55:30 +02:00
Avi Kivity
239f4a3bf5 memcache: remove unused subdevice::_length
Noticed by clang.
2014-11-26 14:55:01 +02:00
Raphael S. Carvalho
35f37a4235 memcache: generate flashcache
flashcached.cc and memcached.cc files were created to generate
flashcached and memcached respectively through a template parameter.
2014-11-25 09:10:33 -02:00
Raphael S. Carvalho
300b310a27 memcache: move ./memcached.cc to ./memcache.cc
Actual purpose is explained by the subsequent commit.
2014-11-25 09:10:33 -02:00
Raphael S. Carvalho
087038bd47 memcache: flashcache integration
flashcached isn't generated by the build process yet, please check
subsequent commits.
2014-11-25 09:05:13 -02:00
Tomasz Grabiec
e85371112b memcached: optimize handle_get()
We don't really need to copy keys as the parser is not reused until
we're done.

Also, in case of a single key we don't use map_reduce() which
saves us one allocation (reducer).
2014-11-20 13:25:07 +02:00
Tomasz Grabiec
7737871ea0 memcached: move data rather than copy it 2014-11-20 13:25:06 +02:00
Tomasz Grabiec
c262060d92 memcache: avoid vprintf()
Improves memaslap UDP posix throughput on my laptop by 40% (from 73k to 105k).

When item is created we cache flags and size part of the response so
that there's no need to call expensive string formatting in get(). The
down side is that this pollutes "item" object with protocol-specific
field, but since ASCII is the only protocol which is supported now and
it's not like we can't fix it later, I think it's fine.
2014-11-13 22:22:07 +02:00
Tomasz Grabiec
b0dd9e736c memcached: SMP support
There is a separate DB per core, each serving a subset of the key
space. From the outside in appears to behave as one DB.

item_key type was changed to include the hash so that we calculate the
hash only once. The same hash is used for sharding and hashing. No
need for store_hash<> option on unordered_set<> any more.

Some seastar-specific and hashtable-specific stats were moved from the
general "stats" command into "stats hash", which shows per-core
statistics.
2014-11-11 13:52:23 +02:00
Tomasz Grabiec
39a688d173 memcache: udp: remove dead code 2014-11-09 17:03:37 +02:00
Raphael S. Carvalho
3878d387f0 memcache: udp: allocate conversation state
Fix UDP for memcache with native stack

memcached: apps/memcached/memcached.cc:807:
void memcache::assert_resolved(future<>): Assertion `f.available()'
failed.

Tomek writes:
UDP path relied on the fact that handle() could not block, because
the output stream does not block, and passed references to variables
which live on stack. Since you now can block in handle_get(), this
no longer holds. We should chnage that, ie allocate conversation
state like we do in TCP.

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2014-11-06 18:21:56 +02:00
Gleb Natapov
d698811bdd fix smp broadcast packet handling
Some packets, like arp replies, are broadcast to all cpus for handling,
but only packet structure is copied for each cpu, the actual packet data
is the same for all of them. Currently networking stack mangles a
packet data during its travel up the stack while doing ntoh()
translations which cannot obviously work for broadcaster packets. This
patches fixes the code to not modify packet data while doing ntoh(), but
do it in a stack allocated copy of a data instead.
2014-11-06 10:30:30 +02:00
Tomasz Grabiec
57861d39ce memcache: add 'stats hash' command
Prints some details about hashtable usage.
2014-10-28 12:33:00 +02:00
Avi Kivity
6dcf24f98d Move contents of async-action.hh into future-util.hh 2014-10-27 19:28:10 +02:00
Gleb Natapov
544a990f80 timer_set: fix expired time cancellation
Expired timer cancellation is broken since timer_set assumes that a
timer that is being canceled is not expired yet. This patch fixes the
problem by moving expired timers management outside timer_set and
letting the code that uses it to managed cancellation of expired timers.
In memcached it can never happen, in core each queued timer gets expired
flag that tells if timer is queued in a timer set or in expired timer
list.
2014-10-22 18:27:00 +03:00
Tomasz Grabiec
a8c64386b2 memcache: enable hash caching and hash comparison
std::unordred_map does it by default for std::string. We switched to
boost::intrusive::unordered_set<>, which does not do it by default for
any key. I see ~4% improvement in throughput with this.
2014-10-22 17:41:57 +03:00
Tomasz Grabiec
1d439ec2b6 memcache: try to handle hashtable resize failure
Big hashtables may fail to resize. Let's not crash when this happens
but evict some items and continue.
2014-10-21 16:58:35 +02:00
Tomasz Grabiec
137d465b72 memcache: hook up memory reclaimer
It implements a very simple reclaimer. When triggered tries to free
around 5 MB of data. This assumes that this amount is more than anyone
would want to allocate between low-memory event is detected and the
reclaimer task runs. This amount was chosen arbitrarily and I am not
sure if this amount is right.
2014-10-21 16:58:35 +02:00
Tomasz Grabiec
bd31ea1f6a memcache: add stats for expired items 2014-10-21 16:43:09 +02:00
Tomasz Grabiec
0f1c499154 memcache: track items in an LRU list 2014-10-21 16:43:09 +02:00
Tomasz Grabiec
658fe77afa memcache: switch cache to use boost::intrusive::unordered_set
This will allow us to have LRU evictions and removal of expired items
which don't involve key lookups.
2014-10-21 16:43:09 +02:00
Pekka Enberg
6723c0cbdd apps/memcache => apps/memcached
The protocol is called the "memcache protocol" but the server should
follow the same naming convention as httpd does.

It should not be a big deal but it annoys the hell out of simple people
like myself who have their brain hard-wired to type the final "d"...

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
2014-10-21 17:30:14 +03:00