Commit Graph

55 Commits

Author SHA1 Message Date
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
Avi Kivity
6f48e27bfd httpd: simplify connection termination
The current implementation uses a sort of "manual reference counting"; any
place which may be the last one using the connection checks if it is indeed
the last one, and if so, deletes the connection object.

With recent changes this has become unwields, as there are too many cases
to track.

To fix, we separate the connection into two streams: a read() stream that
is internally serialized (only one request is parsed at a time) and that
returns when there are no more requests to parse, and a respond() stream
that is also internally serialized, and termiantes when the last response
has been written.  The caller then waits on the two streams with when_all().
2014-10-30 14:09:47 +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
Avi Kivity
4af8036677 http: convert to use distributed<> infrastructure 2014-10-26 13:34:31 +02:00
Asias He
c3d225eb5f httpd: Support close initiated on server side
This makes ab work:

$ ab -n 1000 http://ip:10000/
2014-10-23 12:57:32 +03:00
Asias He
0b3fc256b6 httpd: Drop dead code 2014-10-23 10:30:40 +03:00
Asias He
b7ab4621fe httpd: Allow tune the http server port 2014-10-23 10:30:40 +03: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
Asias He
5d19306435 httpd: Delete connection when client closes
When client closes the connection in one direction, make httpd close the
other direction too. This way, httpd will send back a <FIN> packet to
client after receiving client's <FIN> packet.
2014-10-22 10:27:27 +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
Tomasz Grabiec
f00bc22067 memcache: add support for 'incr' and 'decr' commands 2014-10-18 12:59:59 +02:00
Tomasz Grabiec
3093e2c543 memcache: make data changes atomic
Transmission of data is not atomic so we cannot replace item's fields
in-place. This can lead to inconsistencies in "get" responses. We
should rather allocate a new item object replacing the one which is in
the cache.
2014-10-18 12:59:59 +02:00
Tomasz Grabiec
7ae9178439 memcache: introduce 'stats' command
Our version prints only a subset of statistics printed by stock memcache.
2014-10-18 12:59:59 +02:00
Tomasz Grabiec
287ad01f76 memcache: make cache::size() return only live items 2014-10-18 12:59:59 +02:00
Tomasz Grabiec
7c9e31a0b2 memcache: add 'cas' and 'gets' commands 2014-10-18 12:59:59 +02:00
Tomasz Grabiec
5c649c54fb memcache: add support for 'add' and 'replace' commands 2014-10-18 12:59:59 +02:00
Tomasz Grabiec
f3ebe8abe9 memcache: support 'noreply' on 'set' and 'delete' 2014-10-18 12:59:58 +02:00
Tomasz Grabiec
84d5b7098f memcache: implement 'version' command 2014-10-18 12:59:58 +02:00
Tomasz Grabiec
f2b1d16ce5 memcache: implement 'flush_all' command 2014-10-18 12:59:58 +02:00
Tomasz Grabiec
5d6eaaea33 ragel: reset string builder on init
Otherwise it will contain stale data from previous unsuccessful pass.
2014-10-16 12:24:30 +02:00
Tomasz Grabiec
c1dc3b0d53 memcache: handle end of stream properly on TCP 2014-10-16 11:45:32 +02:00
Tomasz Grabiec
cf2d72a360 memcache: recover from errors in the TCP stream
This is mostly to make memcapable from libmemcached happy.

When client issued a bad command, we should discard all data we have
so that the next command on that connection can succeed.
2014-10-16 09:11:11 +02:00
Tomasz Grabiec
ec42ca860a memcache: add TCP server 2014-10-15 15:59:42 +02:00
Tomasz Grabiec
d575ad2dfb memcache: introduce periodic stats printer 2014-10-15 15:59:42 +02:00
Tomasz Grabiec
88537320f3 memcache: initial version
Supports UDP and subset of ASCII protocol with the following commands:
get, set and delete.
2014-10-15 15:59:42 +02:00
Tomasz Grabiec
eac955cc73 core: simplify output_stream::write() and flush() results
The result is not used for anything and I am not sure what it could be
used for, as the result carries little (write) to none (flush)
information. So I went ahead and simplified it to be future<> so that
it is easier to return it in places which expect future<>.
2014-10-09 20:02:11 +03:00
Gleb Natapov
304f6a317e Run httpd on all available cpus 2014-10-07 11:04:07 +03:00
Tomasz Grabiec
3775dae6fb net: convert ipv4_addr.host from array to uint32_t
It will be easier to convert it to a format on which the native stack
works.
2014-10-06 18:34:28 +02:00
Avi Kivity
c8b602e713 httpd: switch to circular_buffer 2014-10-02 14:32:34 +03:00
Avi Kivity
1472c24533 httpd: replace custom parser with Ragel based parser 2014-09-29 15:17:42 +03:00
Tomasz Grabiec
4f94fc46ce httpd: use app_template 2014-09-24 15:11:35 +03:00
Gleb Natapov
736b07b2b6 Run http with smp
This patches shows what change is needed for http to run with multiple
event loops. This is not very useful still because actual work is not
yet distributed.
2014-09-24 13:12:38 +03:00
Avi Kivity
46402831ae httpd: remove unused fields to make clang happy 2014-09-22 17:18:06 +03:00
Tomasz Grabiec
52ab797536 rename engine::start() to engine::when_started()
The imperative form suggests that in addition to returning a future it
performs some action and thus is needed regardless of whether we want
to add a callback or not. But in fact it does not do anything, just
gives away a future.

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
2014-09-16 09:59:13 +03:00
Avi Kivity
e0c111563f httpd: simplify exception handler
No need to rename 'this' (still strange that it has to be used as
this->maybe_done()).
2014-09-15 09:50:13 +03:00
Avi Kivity
b81869e541 httpd: use modern future chaining style
There's no need to create a temporary promise and pass it around; instead
use future chaining to accomplish the same result.
2014-09-15 09:43:15 +03:00
Asias He
9b294f2829 httpd: Print port info on startup
Signed-off-by: Asias He <asias@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
2014-09-13 07:23:40 +03:00
Avi Kivity
b6d85fc6a6 s/the_reactor/engine/g
Things named "engine" are 20% faster.
2014-09-10 15:46:33 +03:00
Avi Kivity
bb26a0c08a httpd: allow switching network stack 2014-09-10 13:46:54 +03:00