The script.max_compilations_rate
setting in Elasticsearch controls the maximum rate at which new scripts can be compiled. This setting helps protect the cluster from excessive resource consumption due to frequent script compilations.
- Default Value: 150/5m (150 compilations per 5-minute window)
- Possible Values: A number followed by a time unit (e.g., 75/5m, 200/1h)
- Recommendation: The default value is suitable for most use cases. Adjust based on your specific needs and cluster capabilities.
This setting limits the number of new script compilations allowed within a specified time window. It's designed to prevent potential performance issues or denial of service attacks that could arise from compiling too many scripts too quickly.
Example
To change the script.max_compilations_rate
setting using the cluster settings API:
PUT _cluster/settings
{
"persistent": {
"script.max_compilations_rate": "200/1h"
}
}
This example increases the compilation rate to 200 per hour. You might want to increase this rate if you have a high-performance cluster that frequently uses new or updated scripts. However, be cautious, as setting it too high could lead to excessive resource consumption.
Common Issues or Misuses
- Setting the rate too low can cause legitimate script compilations to fail, potentially disrupting operations that rely on scripting.
- Setting the rate too high might not provide adequate protection against script compilation abuse.
- Misunderstanding the setting as a performance optimization tool rather than a protective measure.
Do's and Don'ts
Do's:
- Monitor script compilation rates and adjust the setting based on your observed needs.
- Consider increasing the rate if you frequently update scripts or use dynamic scripting.
- Use this setting in conjunction with other security measures to protect your cluster.
Don'ts:
- Don't set an excessively high rate without considering the potential impact on cluster resources.
- Don't ignore compilation failures that might be caused by this rate limit.
- Don't rely solely on this setting for script security; always validate and sanitize script inputs.
Frequently Asked Questions
Q: What happens if the script compilation rate is exceeded?
A: When the rate is exceeded, new script compilation requests will be rejected until the rate falls below the limit. This can result in errors for operations that require new script compilations.
Q: Can I disable this rate limiting entirely?
A: While it's possible to set an extremely high rate effectively disabling the limit, it's not recommended as it removes an important protection mechanism against potential abuse or unintended resource consumption.
Q: How does this setting affect stored scripts?
A: Stored scripts are compiled only once when they are added or updated, so they are less likely to be affected by this rate limit compared to inline scripts that are compiled on each use.
Q: Is this setting node-specific or cluster-wide?
A: The script.max_compilations_rate
setting is cluster-wide. It applies to all nodes in the cluster and helps maintain consistent script compilation behavior across the entire cluster.
Q: How can I monitor script compilation rates in my cluster?
A: You can use the _nodes/stats/script
API endpoint to retrieve statistics about script compilations, including compilation rates and cache usage, which can help you tune this setting appropriately.