Troubleshooting and Best Practices

What happens when more Workers are allocated for a Function?

Couchbase Server for a Function limits the maximum number of workers to 10. This upper limit is configured for system optimization purposes. In the Function definition, if the number of workers exceeds the set threshold, then the system automatically generates a warning message. However, the warning message does not prevent deployment of the Function .

Warning Message: "There are <number_of_workers> eventing workers configured to run. System performance may be impacted."

Can Couchbase Server process cURL commands?

Support for cURL commands in Functions is for demo purposes. Ensure not to use cURL commands in your production environment.

The system generates a warning message. However, the warning message does not prevent the Function deployment.

Warning Message: "Handler <function_name> uses Developer Preview features. Do not use in production environments."

cURL commands are a Developer Preview feature intended for development purposes only, do not use them in production; no Enterprise Support is provided for Developer Preview features.

When should developers use the try-catch block in Function handlers?

As a best practice to debug logical errors in the Function handler code, it is recommended that developers use the try-catch block.

A sample try-catch block is provided for reference:

function OnUpdate(doc, meta)
{
  log('document', doc);
  try {
    var time_rand = random_gen();
    dst_bucket[meta.id + time_rand] = doc;
  }
  catch(e)
  {
    log(e);
  }
}

What are bucket allocation considerations during a Function definition?

Function handlers can trigger data mutations. To avoid a cyclic generation of data changes, ensure that you carefully consider the below aspects while specifying source and destination buckets:

  • Avoid infinite recursions. If you are using a series of handlers, then ensure that destination buckets to which event handlers perform a write operation, do not have other Function handlers configured to listen and track data mutations.
    Couchbase Server can flag simple infinite recursions. However, in a long chain of source and destination buckets with a series of handlers, a complex infinite recursion condition may occur. As a developer, carefully consider these cases.

  • As a best practice, ensure that buckets to which the Function handler performs a write operation do not have other handlers configured for tracking data mutations.

In the cluster, I notice a sharp increase in the Timeouts Statistics. What are my next steps?

When the Timeout Statistics shows a sharp increase, it may be due to two possible scenarios:

  • Increase in execution time: When the handler execution time increases, the Function execution latency gets affected, and this in turn, leads to Function backlog and failure conditions.

  • Script timeout value: When the script timeout attribute value is not correctly configured, then you encounter timeout conditions frequently.

As a workaround, it is recommended to increase the script timeout value. Ensure that you configure the script timeout value after carefully evaluating the execution latency of the Function.