* 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 <yaz++/z-assoc.h>
class Yaz_Proxy;
+#define MAX_ZURL_PLEX 10
+
struct Yaz_RecordCache_Entry;
class YAZ_EXPORT Yaz_ProxyConfig {
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();
<target default="1" name="voyager">
<!-- default target -->
<url>z3950.loc.gov:7090/voyager</url>
+ <url>z3950.loc.gov:7094/voyager</url>
<keepalive>1</keepalive>
<limit><!-- limits .. -->
<bandwidth>200000</bandwidth>
</limit>
<query type="1" value="10" error="114"/>
<target-timeout>180</target-timeout>
- <client-timeout>60</client-timeout>
+ <client-timeout>120</client-timeout>
<syntax type="usmarc"/>
<syntax type="*" error="238"/>
</target>
<target name="localhost">
<url>localhost:9999</url>
+ <url>localhost:9998</url>
<keepalive>0</keepalive>
<limit><!-- limits .. -->
<bandwidth>50000</bandwidth>
<target name="*">
<!-- everything else -->
</target>
- <max-clients>1</max-clients>
+ <max-clients>100</max-clients>
</proxy>
* 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 <ctype.h>
int *target_idletime,
int *client_idletime)
{
+ int no_url = 0;
ptr = ptr->children;
for (; ptr; ptr = ptr->next)
{
&& !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"))
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 &&
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);
}
* 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 <assert.h>
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; i<MAX_ZURL_PLEX; i++)
+ zurl_in_use[i] = 0;
+ for (c = m_parent->m_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);
if (!m_proxyTarget)
{
+ const char *url[MAX_ZURL_PLEX];
const char *proxy_host = get_proxy(oi);
if (proxy_host)
{
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);
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)
{