1 ;;; -*- Mode: Common-Lisp -*-
3 ;;; Copyright (c) 2006, Abhijit 'quasi' Rao. All rights reserved.
4 ;;; Copyright (c) 2006, Cleartrip Travel Services.
5 ;;; Copyright (c) 2011 Kevin Rosenberg
7 ;;; Redistribution and use in source and binary forms, with or without
8 ;;; modification, are permitted provided that the following conditions
11 ;;; * Redistributions of source code must retain the above copyright
12 ;;; notice, this list of conditions and the following disclaimer.
14 ;;; * Redistributions in binary form must reproduce the above
15 ;;; copyright notice, this list of conditions and the following
16 ;;; disclaimer in the documentation and/or other materials
17 ;;; provided with the distribution.
19 ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED
20 ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23 ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
25 ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 (in-package #:memcache)
32 (defvar *memcache* nil
33 "Represents a particular Memcached server")
35 (defvar *use-pool* nil
36 "Default value for the USE-POOL keyword parameter in memcached functions")
38 (defvar *pool-get-trys?* nil
39 "If true then it will try to wait and sleep for a while if pool item in unavailable,
40 if nil then will return immideatly")
44 (string (code-char 13))
45 (string (code-char 10))))
47 (defconstant* +mc-END-ret+
54 (:conc-name mc-stats-)
56 (lambda (struct stream depth)
57 (declare (ignore depth))
58 (print-unreadable-object (struct stream :type t :identity t)
59 (format stream "pid:~A size:~d MB curr:~d total:~D"
61 (/ (mc-stats-limit-maxbytes struct) 1024 1024)
62 (mc-stats-curr-items struct)
63 (mc-stats-curr-items-total struct))))))
64 "The structure which holds the statistics from the memcached server. The fields are :
65 field-name accessor-function documentation
66 ---------- ----------------- -------------
67 pid mc-stats-pid Process id of this server process
68 uptime mc-stats-uptime Number of seconds this server has been running
69 time mc-stats-time current UNIX time according to the server
70 version mc-stats-version Version string of this server
71 rusage-user mc-stats-rusage-user Accumulated user time for this process
72 rusage-system mc-stats-rusage-system Accumulated system time for this process
73 curr-items mc-stats-curr-items Current number of items stored by the server
74 curr-items-total mc-stats-curr-items-total
75 curr-connections mc-stats-curr-connections Number of open connections
76 total-connections mc-stats-total-connections Total number of connections opened since the server started running
77 connection-structures mc-stats-connection-structures Number of connection structures allocated by the server
78 cmd-get mc-stats-cmd-get Cumulative number of retrieval requests
79 cmd-set mc-stats-cmd-set Cumulative number of storage requests
80 get-hits mc-stats-get-hits Number of keys that have been requested and found present
81 get-misses mc-stats-get-misses Number of items that have been requested and not found
82 bytes-read mc-stats-bytes-read Total number of bytes read by this server from network
83 bytes-written mc-stats-bytes-written Total number of bytes sent by this server to network
84 limit-maxbytes mc-stats-limit-maxbytes Number of bytes this server is allowed to use for storage.
87 pid uptime time version rusage-user rusage-system curr-items curr-items-total
88 curr-connections total-connections connection-structures cmd-get cmd-set
89 get-hits get-misses bytes-read bytes-written limit-maxbytes)
92 ;;; The main class which represents the memcached server
99 :documentation "Name of this Memcache instance")
102 :initform "127.0.0.1"
105 :documentation "The host name of the Memcached server for this instance.")
111 :documentation "The port on which the Memcached server this instance represents runs")
112 (memcached-server-storage-size
114 :reader memcached-server-storage-size
116 :documentation "Memory allocated to the Memcached Server")
123 (:documentation "This class represents an instance of the Memcached server"))
126 (defconstant* +membase17-stat-names+
127 '("accepting_conns" "auth_cmds" "auth_errors" "bucket_active_conns" "bucket_conns"
128 "bytes_read" "bytes_written" "cas_badval" "cas_hits" "cas_misses" "cmd_flush"
129 "cmd_get" "cmd_set" "conn_yields" "connection_structures" "curr_connections"
130 "curr_items" "curr_items_tot" "daemon_connections" "decr_hits" "decr_misses"
131 "delete_hits" "delete_misses" "ep_bg_fetched" "ep_commit_num" "ep_commit_time"
132 "ep_commit_time_total" "ep_data_age" "ep_data_age_highwat" "ep_db_cleaner_status"
133 "ep_db_strategy" "ep_dbinit" "ep_dbname" "ep_dbshards" "ep_diskqueue_drain"
134 "ep_diskqueue_fill" "ep_diskqueue_items" "ep_diskqueue_memory"
135 "ep_diskqueue_pending" "ep_expired" "ep_flush_all" "ep_flush_duration"
136 "ep_flush_duration_highwat" "ep_flush_duration_total" "ep_flush_preempts"
137 "ep_flusher_state" "ep_flusher_todo" "ep_io_num_read" "ep_io_num_write"
138 "ep_io_read_bytes" "ep_io_write_bytes" "ep_item_begin_failed"
139 "ep_item_commit_failed" "ep_item_flush_expired" "ep_item_flush_failed"
140 "ep_items_rm_from_checkpoints" "ep_kv_size" "ep_latency_arith_cmd"
141 "ep_latency_get_cmd" "ep_latency_store_cmd" "ep_max_data_size" "ep_max_txn_size"
142 "ep_mem_high_wat" "ep_mem_low_wat" "ep_min_data_age" "ep_num_active_non_resident"
143 "ep_num_checkpoint_remover_runs" "ep_num_eject_failures" "ep_num_eject_replicas"
144 "ep_num_expiry_pager_runs" "ep_num_non_resident" "ep_num_not_my_vbuckets"
145 "ep_num_pager_runs" "ep_num_value_ejects" "ep_onlineupdate"
146 "ep_onlineupdate_revert_add" "ep_onlineupdate_revert_delete"
147 "ep_onlineupdate_revert_update" "ep_oom_errors" "ep_overhead" "ep_pending_ops"
148 "ep_pending_ops_max" "ep_pending_ops_max_duration" "ep_pending_ops_total"
149 "ep_queue_age_cap" "ep_queue_size" "ep_storage_age" "ep_storage_age_highwat"
150 "ep_storage_type" "ep_store_max_concurrency" "ep_store_max_readers"
151 "ep_store_max_readwrite" "ep_tap_bg_fetch_requeued" "ep_tap_bg_fetched"
152 "ep_tap_keepalive" "ep_tmp_oom_errors" "ep_too_old" "ep_too_young"
153 "ep_total_cache_size" "ep_total_del_items" "ep_total_enqueued" "ep_total_new_items"
154 "ep_total_persisted" "ep_uncommitted_items" "ep_vb_total" "ep_vbucket_del"
155 "ep_vbucket_del_fail" "ep_version" "ep_warmed_up" "ep_warmup" "ep_warmup_dups"
156 "ep_warmup_oom" "ep_warmup_thread" "ep_warmup_time" "get_hits" "get_misses"
157 "incr_hits" "incr_misses" "libevent" "limit_maxbytes" "listen_disabled_num"
158 "mem_used" "pid" "pointer_size" "rejected_conns" "rusage_system" "rusage_user"
159 "threads" "time" "total_connections" "uptime" "vb_active_curr_items"
160 "vb_active_eject" "vb_active_ht_memory" "vb_active_itm_memory" "vb_active_num"
161 "vb_active_num_non_resident" "vb_active_ops_create" "vb_active_ops_delete"
162 "vb_active_ops_reject" "vb_active_ops_update" "vb_active_perc_mem_resident"
163 "vb_active_queue_age" "vb_active_queue_drain" "vb_active_queue_fill"
164 "vb_active_queue_memory" "vb_active_queue_pending" "vb_active_queue_size"
165 "vb_dead_num" "vb_pending_curr_items" "vb_pending_eject" "vb_pending_ht_memory"
166 "vb_pending_itm_memory" "vb_pending_num" "vb_pending_num_non_resident"
167 "vb_pending_ops_create" "vb_pending_ops_delete" "vb_pending_ops_reject"
168 "vb_pending_ops_update" "vb_pending_perc_mem_resident" "vb_pending_queue_age"
169 "vb_pending_queue_drain" "vb_pending_queue_fill" "vb_pending_queue_memory"
170 "vb_pending_queue_pending" "vb_pending_queue_size" "vb_replica_curr_items"
171 "vb_replica_eject" "vb_replica_ht_memory" "vb_replica_itm_memory" "vb_replica_num"
172 "vb_replica_num_non_resident" "vb_replica_ops_create" "vb_replica_ops_delete"
173 "vb_replica_ops_reject" "vb_replica_ops_update" "vb_replica_perc_mem_resident"
174 "vb_replica_queue_age" "vb_replica_queue_drain" "vb_replica_queue_fill"
175 "vb_replica_queue_memory" "vb_replica_queue_pending" "vb_replica_queue_size"