Hey there,
We are using Couchbase cluster for a high-load ad-serving system.
thousands of HTTP requests are coming to our load balancer in a second.
Every HTTP request is handled by one of our application server (which is web server with couchbase C client)
We have written a C code that loaded into our HTTP web server, and every request is handled by the Web server, being filtered with the relevant parameters and headers, and then it will go with the Couchbase C client to the cluster to get a specific documnet and to increase it’s counter document.
For every single HTTP request we are using “lcb_create” to create the instance and then “lcb_connect” if the instance was created with no errors.
I’m experiencing an hectic problem with executing this code thousands of times in a second.
every ~400-500 requests we are getting a connection error:
“ERROR: Connection failure (0x18), Could not connect to server within allotted time”
seems like the couchbase cluster can not handle this amount of connections per second.
This is the current code we are using for connecting the cluster:
err = lcb_create(&instance, &create_options);
if (err != LCB_SUCCESS) {
syslog(LOG_DEBUG,“Failed to create libcouchbase instance: %s\n”, lcb_strerror(NULL, err));
return 1;
}
(void)lcb_set_error_callback(instance, error_callback);
/* Initiate the connect sequence in libcouchbase */
if ((err = lcb_connect(instance)) != LCB_SUCCESS) {
syslog(LOG_DEBUG,“Failed to initiate connect: %s\n”, lcb_strerror(NULL, err));
lcb_destroy(instance);
return 1;
}
As per my understanding, “lcb_create” and “lcb_connect” are two methods that require large amount of resources from the cluster , and therefore the couchbase is having diffucults to respond, and thats why we are getting this connections errors.
Maybe we should somehow gather our connections into one instance and do not execute “lcb_create” and “lcb_connect” for every single request.
Is there anyway to implement it in C code ?
Is it possible to check if there is already an instance that was created, and to use it instead of creating an instance every time ?
Maybe “lcb_create_io_ops” can help here ?
- Just to clarify
the cluster is not cpu-loaded. the servers are fine in terms of IOPS\ CPU RAM and SWAP.
we are really frustrated,
we would like to hear any opinion from you.
Thank you very much.