Hi [email protected],

I'd like to propose a new public API to address a performance issue
identified in GitHub issue #12292:
https://github.com/apache/trafficserver/issues/12292


*The Problem*Some overridable string configurations require parsing before
they can be applied to a transaction. For example,
proxy.config.hostdb.ip_resolve needs to parse a string like "ipv4;ipv6"
into a host resolution preference order, and
proxy.config.http.negative_caching_list needs to parse "204 305 403" into a
status code bitset.

Currently, when plugins like conf_remap use TSHttpTxnConfigStringSet() to
apply these configurations, the parsing happens on every request. For
high-traffic deployments applying the same configuration value repeatedly,
this is expensive.


*Proposed Solution*Add three new functions to ts.h that allow plugins to
pre-convert string values once at load time:

// Pre-convert a string value (or nullptr for NULL/unset).
TSReturnCode TSConfigStringPreconvert(TSOverridableConfigKey conf, const
char *value, int length, TSPreconvertedConfigValue *result);

// Apply the pre-converted value to a transaction.
TSReturnCode TSHttpTxnConfigPreconvertedValueSet(TSHttpTxn txnp,
TSOverridableConfigKey conf, TSPreconvertedConfigValue value);

// Free the pre-converted value.
void TSPreconvertedConfigValueDestroy(TSPreconvertedConfigValue value);

The TSPreconvertedConfigValue is an opaque handle that stores either the
pre-parsed representation (for configs that need special parsing) or the
original string (for configs that don't).
Passing nullptr as the value represents a NULL/unset configuration, which
is distinct from an empty string.


*Example Usage*

   // At plugin initialization (called once).
   TSPreconvertedConfigValue g_preconverted = nullptr;

   TSReturnCode
   TSRemapNewInstance(int argc, char* argv[], void** ih, ...)
   {
      TSConfigStringPreconvert(
         TS_CONFIG_HTTP_NEGATIVE_CACHING_LIST,
         "400 404 500",
         -1, // The implementation will use strlen on the above string.
         &g_preconverted);
      return TS_SUCCESS;
   }

   // At remap time (called on every matching request).
   TSRemapStatus
   TSRemapDoRemap(void* ih, TSHttpTxn rh, TSRemapRequestInfo* rri)
   {
      // Pass the preconverted value - no string parsing needed
      // for each transaction.
      TSHttpTxnConfigPreconvertedValueSet(
         rh,
         TS_CONFIG_HTTP_NEGATIVE_CACHING_LIST,
         g_preconverted);
      return TSREMAP_NO_REMAP;
   }

   // At plugin destruction (called once).
   void
   TSRemapDeleteInstance(void* ih)
   {
      TSPreconvertedConfigValueDestroy(g_preconverted);
   }

For more details, see the following draft PR:
https://github.com/apache/trafficserver/pull/12734

Please let me know if you have any concerns.

Thanks,
Brian Neradt

-- 
"Come to Me, all who are weary and heavy-laden, and I will
give you rest. Take My yoke upon you and learn from Me, for
I am gentle and humble in heart, and you will find rest for
your souls. For My yoke is easy and My burden is light."

    ~ Matthew 11:28-30

Reply via email to