From 8cd77956b745e79b984bc0c9b74989aeae8dd49d Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 8 Oct 2003 09:32:48 +0000 Subject: [PATCH] Multiplexing --- include/yaz++/proxy.h | 5 ++++- src/config.xml | 6 ++++-- src/yaz-proxy-config.cpp | 19 ++++++++++++++----- src/yaz-proxy.cpp | 39 ++++++++++++++++++++++++++++++++++----- 4 files changed, 56 insertions(+), 13 deletions(-) diff --git a/include/yaz++/proxy.h b/include/yaz++/proxy.h index 7326391..2a0b3e1 100644 --- a/include/yaz++/proxy.h +++ b/include/yaz++/proxy.h @@ -2,7 +2,7 @@ * Copyright (c) 1998-2003, Index Data. * See the file LICENSE for details. * - * $Id: proxy.h,v 1.12 2003-10-08 08:53:08 adam Exp $ + * $Id: proxy.h,v 1.13 2003-10-08 09:32:48 adam Exp $ */ #include @@ -16,6 +16,8 @@ class Yaz_Proxy; +#define MAX_ZURL_PLEX 10 + struct Yaz_RecordCache_Entry; class YAZ_EXPORT Yaz_ProxyConfig { @@ -169,6 +171,7 @@ class YAZ_EXPORT Yaz_Proxy : public Yaz_Z_Assoc { Z_APDU *handle_query_validation(Z_APDU *apdu); Z_APDU *handle_syntax_validation(Z_APDU *apdu); + const char *load_balance(const char **url); public: Yaz_Proxy(IYaz_PDU_Observable *the_PDU_Observable); ~Yaz_Proxy(); diff --git a/src/config.xml b/src/config.xml index cf9f8c3..d8d5045 100644 --- a/src/config.xml +++ b/src/config.xml @@ -4,6 +4,7 @@ z3950.loc.gov:7090/voyager + z3950.loc.gov:7094/voyager 1 200000 @@ -12,12 +13,13 @@ 180 - 60 + 120 localhost:9999 + localhost:9998 0 50000 @@ -33,5 +35,5 @@ - 1 + 100 diff --git a/src/yaz-proxy-config.cpp b/src/yaz-proxy-config.cpp index 1abd49f..5fc164b 100644 --- a/src/yaz-proxy-config.cpp +++ b/src/yaz-proxy-config.cpp @@ -2,7 +2,7 @@ * Copyright (c) 1998-2003, Index Data. * See the file LICENSE for details. * - * $Id: yaz-proxy-config.cpp,v 1.5 2003-10-08 08:15:01 adam Exp $ + * $Id: yaz-proxy-config.cpp,v 1.6 2003-10-08 09:32:49 adam Exp $ */ #include @@ -126,6 +126,7 @@ void Yaz_ProxyConfig::return_target_info(xmlNodePtr ptr, int *target_idletime, int *client_idletime) { + int no_url = 0; ptr = ptr->children; for (; ptr; ptr = ptr->next) { @@ -133,8 +134,11 @@ void Yaz_ProxyConfig::return_target_info(xmlNodePtr ptr, && !strcmp((const char *) ptr->name, "url")) { const char *t = get_text(ptr); - if (t) - *url = t; + if (t && no_url < MAX_ZURL_PLEX) + { + url[no_url++] = t; + url[no_url] = 0; + } } if (ptr->type == XML_ELEMENT_NODE && !strcmp((const char *) ptr->name, "keepalive")) @@ -452,9 +456,11 @@ void Yaz_ProxyConfig::get_target_info(const char *name, xmlNodePtr ptr; if (!m_proxyPtr) { - *url = name; + url[0] = name; + url[1] = 0; return; } + url[0] = 0; for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next) { if (ptr->type == XML_ELEMENT_NODE && @@ -473,7 +479,10 @@ void Yaz_ProxyConfig::get_target_info(const char *name, if (ptr) { if (name) - *url = name; + { + url[0] = name; + url[1] = 0; + } return_target_info(ptr, url, keepalive, limit_bw, limit_pdu, limit_req, target_idletime, client_idletime); } diff --git a/src/yaz-proxy.cpp b/src/yaz-proxy.cpp index 49992a3..e7c1ad2 100644 --- a/src/yaz-proxy.cpp +++ b/src/yaz-proxy.cpp @@ -2,7 +2,7 @@ * Copyright (c) 1998-2003, Index Data. * See the file LICENSE for details. * - * $Id: yaz-proxy.cpp,v 1.51 2003-10-08 08:15:01 adam Exp $ + * $Id: yaz-proxy.cpp,v 1.52 2003-10-08 09:32:49 adam Exp $ */ #include @@ -158,6 +158,35 @@ char *Yaz_Proxy::get_proxy(Z_OtherInformation **otherInfo) return 0; } +const char *Yaz_Proxy::load_balance(const char **url) +{ + int zurl_in_use[MAX_ZURL_PLEX]; + Yaz_ProxyClient *c; + int i; + + for (i = 0; im_clientPool; c; c = c->m_next) + { + for (i = 0; url[i]; i++) + if (!strcmp(url[i], c->get_hostname())) + zurl_in_use[i]++; + } + int min = 100000; + const char *ret = 0; + for (i = 0; url[i]; i++) + { + yaz_log(LOG_LOG, "%s zurl=%s use=%d", + m_session_str, url[i], zurl_in_use[i]); + if (min > zurl_in_use[i]) + { + ret = url[i]; + min = zurl_in_use[i]; + } + } + return ret; +} + Yaz_ProxyClient *Yaz_Proxy::get_client(Z_APDU *apdu) { assert (m_parent); @@ -170,6 +199,7 @@ Yaz_ProxyClient *Yaz_Proxy::get_client(Z_APDU *apdu) if (!m_proxyTarget) { + const char *url[MAX_ZURL_PLEX]; const char *proxy_host = get_proxy(oi); if (proxy_host) { @@ -178,9 +208,8 @@ Yaz_ProxyClient *Yaz_Proxy::get_client(Z_APDU *apdu) proxy_host = m_default_target; } - const char *url = 0; int client_idletime = -1; - m_config.get_target_info(proxy_host, &url, &m_keepalive, &m_bw_max, + m_config.get_target_info(proxy_host, url, &m_keepalive, &m_bw_max, &m_pdu_max, &m_max_record_retrieve, &m_target_idletime, &client_idletime, &parent->m_max_clients); @@ -189,12 +218,12 @@ Yaz_ProxyClient *Yaz_Proxy::get_client(Z_APDU *apdu) m_client_idletime = client_idletime; timeout(m_client_idletime); } - if (!url) + if (!url[0]) { yaz_log(LOG_LOG, "%s No default target", m_session_str); return 0; } - m_proxyTarget = (char*) xstrdup(url); + m_proxyTarget = (char*) xstrdup(load_balance(url)); } if (cookie && *cookie) { -- 1.7.10.4