From: Dennis Schafroth Date: Thu, 24 Feb 2011 10:13:55 +0000 (+0100) Subject: Merge branch 'master' of ssh://git.indexdata.com/home/git/pub/pazpar2 X-Git-Tag: v1.5.5~40 X-Git-Url: http://lists.indexdata.com/cgi-bin?a=commitdiff_plain;h=e51169ac3c161349e5255517d388f2f5c0cfd12f;hp=330dfe997d099ee125cea44b52adec83af1face6;p=pazpar2-moved-to-github.git Merge branch 'master' of ssh://git.indexdata.com/home/git/pub/pazpar2 --- diff --git a/perf/bash/client_timed.sh b/perf/bash/client_timed.sh index dd4349c..61fc9ab 100755 --- a/perf/bash/client_timed.sh +++ b/perf/bash/client_timed.sh @@ -17,7 +17,7 @@ fi RECORDS=40 QUERY=100 NUM=20 -H="http://localhost:${PORT}/search.pz2" +H="http://127.0.0.1:${PORT}/search.pz2" declare -i MAX_WAIT=2 /usr/bin/time --format "$OF, init, %e" wget -q -O ${TMP_DIR}$OF.init.xml "$H/?command=init&service=${SERVICE}&extra=$OF" 2> ${TMP_DIR}$OF.init.time diff --git a/perf/bash/par.config.dennis b/perf/bash/par.config.dennis index 750f3b1..03c4736 100644 --- a/perf/bash/par.config.dennis +++ b/perf/bash/par.config.dennis @@ -1,9 +1,9 @@ DELAY=0.0001 WAIT=5 NUMBER=10 -ROUNDS=10 +ROUNDS=2 PORT=9005 -SERVICE=perf_t +#SERVICE=perf_t SHUTDOWN=0 SETTINGS="use_url_proxy%5Bcatalog.library.cornell.edu%3A7090%2Fvoyager%5D=0\ &pz%3Acclmap%3Asu%5Bcatalog.library.cornell.edu%3A7090%2Fvoyager%5D=1%3D21+s%3Dal\ diff --git a/perf/bash/par.sh b/perf/bash/par.sh index 881e171..54399d0 100755 --- a/perf/bash/par.sh +++ b/perf/bash/par.sh @@ -6,6 +6,7 @@ ROUNDS=5 PORT=9004 SERVICE=perf_t SHUTDOWN=1 +HOST=127.0.0.1 if test -n "$1"; then . $1 fi @@ -14,7 +15,7 @@ while test $r -lt $ROUNDS; do echo "$r" let i=0 while test $i -lt $NUMBER; do - ./client.sh --outfile=$r.$i --prefix=http://localhost:${PORT}/search.pz2 --service=$SERVICE >$r.$i.log 2>&1 & + ./pp2client.sh --outfile=$r.$i --prefix=http://$HOST:${PORT}/search.pz2 --service=$SERVICE >$r.$i.log 2>&1 & sleep $DELAY let i=$i+1 done diff --git a/src/client.c b/src/client.c index 61e0a8a..e2a363c 100644 --- a/src/client.c +++ b/src/client.c @@ -67,23 +67,26 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "relevance.h" #include "incref.h" -/* client counting (1) , disable client counting (0) */ -#if 1 static YAZ_MUTEX g_mutex = 0; static int no_clients = 0; -static void client_use(int delta) +static int client_use(int delta) { + int clients; if (!g_mutex) yaz_mutex_create(&g_mutex); yaz_mutex_enter(g_mutex); no_clients += delta; + clients = no_clients; yaz_mutex_leave(g_mutex); - yaz_log(YLOG_DEBUG, "%s clients=%d", delta > 0 ? "INC" : "DEC", no_clients); + yaz_log(YLOG_DEBUG, "%s clients=%d", delta == 0 ? "" : (delta > 0 ? "INC" : "DEC"), clients); + return clients; } -#else -#define client_use(x) -#endif + +int clients_count(void) { + return client_use(0); +} + /** \brief Represents client state for a connection to one search target */ struct client { diff --git a/src/http_command.c b/src/http_command.c index 5509b34..f0dc440 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -64,6 +64,23 @@ struct http_sessions { int log_level; }; +static YAZ_MUTEX g_http_session_mutex = 0; +static int g_http_sessions = 0; + +int http_session_use(int delta) +{ + int sessions; + if (!g_http_session_mutex) + yaz_mutex_create(&g_http_session_mutex); + yaz_mutex_enter(g_http_session_mutex); + g_http_sessions += delta; + sessions = g_http_sessions; + yaz_mutex_leave(g_http_session_mutex); + yaz_log(YLOG_DEBUG, "%s sesions=%d", delta == 0 ? "" : (delta > 0 ? "INC" : "DEC"), sessions); + return sessions; + +} + http_sessions_t http_sessions_create(void) { http_sessions_t hs = xmalloc(sizeof(*hs)); @@ -127,6 +144,7 @@ struct http_session *http_session_create(struct conf_service *service, iochan_settimeout(r->timeout_iochan, service->session_timeout); iochan_add(service->server->iochan_man, r->timeout_iochan); + http_session_use(1); return r; } @@ -136,7 +154,7 @@ void http_session_destroy(struct http_session *s) http_sessions_t http_sessions = s->http_sessions; - yaz_log(http_sessions->log_level, "%p Session %u destroyed", s, s->session_id); + yaz_log(http_sessions->log_level, "%p HTTP Session %u destroyed", s, s->session_id); yaz_mutex_enter(http_sessions->mutex); /* only if http_session has no active http sessions on it can be destroyed */ if (s->destroy_counter == s->activity_counter) { @@ -152,13 +170,14 @@ void http_session_destroy(struct http_session *s) yaz_mutex_leave(http_sessions->mutex); if (must_destroy) { /* destroying for real */ - yaz_log(http_sessions->log_level, "%p Session %u destroyed", s, s->session_id); + yaz_log(http_sessions->log_level, "%p HTTP Session %u destroyed", s, s->session_id); iochan_destroy(s->timeout_iochan); destroy_session(s->psession); + http_session_use(-1); nmem_destroy(s->nmem); } else { - yaz_log(http_sessions->log_level, "%p Session %u destroyed delayed. Active clients (%d-%d). Waiting for new timeout.", + yaz_log(http_sessions->log_level, "%p HTTP Session %u destroyed delayed. Active clients (%d-%d). Waiting for new timeout.", s, s->session_id, s->activity_counter, s->destroy_counter); } @@ -566,6 +585,49 @@ static void cmd_termlist(struct http_channel *c) release_session(c,s); } +size_t session_get_memory_status(struct session *session); + +static void cmd_session_status(struct http_channel *c) +{ + struct http_response *rs = c->response; + struct http_session *s = locate_session(c); + size_t session_nmem; + if (!s) + return; + + wrbuf_rewind(c->wrbuf); + wrbuf_puts(c->wrbuf, HTTP_COMMAND_RESPONSE_PREFIX "OK\n"); + wrbuf_printf(c->wrbuf, "%u\n", s->activity_counter); + wrbuf_printf(c->wrbuf, "%zu\n", nmem_total(s->nmem) ); + + session_nmem = session_get_memory_status(s->psession); + wrbuf_printf(c->wrbuf, "%zu\n", session_nmem); + + wrbuf_puts(c->wrbuf, "\n"); + rs->payload = nmem_strdup(c->nmem, wrbuf_cstr(c->wrbuf)); + http_send_response(c); + release_session(c,s); + +} + +int sessions_count(void); +int clients_count(void); +int resultsets_count(void); + +static void cmd_server_status(struct http_channel *c) +{ + struct http_response *rs = c->response; + int sessions = sessions_count(); + int clients = clients_count(); + int resultsets = resultsets_count(); + wrbuf_rewind(c->wrbuf); + wrbuf_puts(c->wrbuf, HTTP_COMMAND_RESPONSE_PREFIX "OK\n"); + wrbuf_printf(c->wrbuf, "Sessions %u Clients: %u Resultsets: %u\n\n", sessions, clients, resultsets); + rs->payload = nmem_strdup(c->nmem, wrbuf_cstr(c->wrbuf)); + http_send_response(c); +} + + static void cmd_bytarget(struct http_channel *c) { @@ -1122,6 +1184,8 @@ struct { { "search", cmd_search }, { "termlist", cmd_termlist }, { "exit", cmd_exit }, + { "sessionstatus", cmd_session_status }, + { "serverstatus", cmd_server_status }, { "ping", cmd_ping }, { "record", cmd_record }, { "info", cmd_info }, diff --git a/src/session.c b/src/session.c index 1c95feb..c46a891 100644 --- a/src/session.c +++ b/src/session.c @@ -94,6 +94,27 @@ struct client_list { struct client_list *next; }; +/* session counting (1) , disable client counting (0) */ +static YAZ_MUTEX g_session_mutex = 0; +static int no_sessions = 0; + +static int session_use(int delta) +{ + int sessions; + if (!g_session_mutex) + yaz_mutex_create(&g_session_mutex); + yaz_mutex_enter(g_session_mutex); + no_sessions += delta; + sessions = no_sessions; + yaz_mutex_leave(g_session_mutex); + yaz_log(YLOG_DEBUG, "%s sesions=%d", delta == 0 ? "" : (delta > 0 ? "INC" : "DEC"), no_sessions); + return sessions; +} + +int sessions_count(void) { + return session_use(0); +} + static void log_xml_doc(xmlDoc *doc) { FILE *lf = yaz_log_file(); @@ -726,8 +747,8 @@ void session_apply_setting(struct session *se, char *dbname, char *setting, void destroy_session(struct session *se) { struct session_database *sdb; - session_log(se, YLOG_DEBUG, "Destroying"); + session_use(-1); session_remove_clients(se); for (sdb = se->databases; sdb; sdb = sdb->next) @@ -741,6 +762,17 @@ void destroy_session(struct session *se) wrbuf_destroy(se->wrbuf); } +size_t session_get_memory_status(struct session *session) { + size_t session_nmem; + if (session == 0) + return 0; + session_enter(session); + session_nmem = nmem_total(session->nmem); + session_leave(session); + return session_nmem; +} + + struct session *new_session(NMEM nmem, struct conf_service *service, unsigned session_id) { @@ -774,7 +806,7 @@ struct session *new_session(NMEM nmem, struct conf_service *service, session->normalize_cache = normalize_cache_create(); session->session_mutex = 0; pazpar2_mutex_create(&session->session_mutex, tmp_str); - + session_use(1); return session; }