Home > other >  Using GBase C API to load balance
Using GBase C API to load balance

Time:02-27

Using GBase CAPI load balancing creation to 8 a cluster of connection, the client should at least put a security group 8 a cluster node IP address to GBase CAPI, such as the host="192.168.1.1; 192.168.1.2 instead, "if a security group 8 a cluster only one node, the client should be passed to GBase CAPI cluster node: the host=" 192.168.1.1;" , semicolon after the IP address of a string is a must, using GBase CAPI load balance to create links to 8 a cluster, if there is no set "GBASE_OPT_USE_SERVER_BALANCE" option value (the value defaults to 0), then the GBase CAPI will between the IP address of the client to load balancing, if set "GBASE_OPT_USE_SERVER_BALANCE" option has a value of 1, then the GBase CAPI between 8 a cluster all nodes to load balance, the following is the use of GBase CAPI code sample of load balancing,
#include
#include
#include
# include "gbase. H"
Int test_banalce ()
{
GBASE * GBASE=NULL;
Char * host="192.168.1.1";
Char * user="gbase";
Char * PWD="111111";
Char * db="test";
Int port=5258;
Int rc=0;
Int use_server_balance=1;
Gbase=gbase_init (NULL);
Gbase_options (gbase, GBASE_OPT_USE_SERVER_BALANCE,
(void *) & amp; Use_server_balance);
if(! Gbase_real_connect (gbase, host, user, PWD, db, port, NULL,
0))
{
Fprintf (stderr, "% d % s \ n \ n", gbase_errno (gbase),
Gbase_error (gbase));
Rc=1;
}
The else
{
Printf (" % s \ n ", gbase_get_host_info (gbase));
}
Gbase_close (gbase);
Return the rc;
}
Int main ()
{
Int I=0;
for(; I & lt; 20; I++)
{
Test_banalce ();
Usleep (2 * 1000);
}
return 0;
}
  • Related