Time-based scaling of Enterprise Search on Elastic Cloud
Does your Elastic Enterprise Search Cloud deployment follow a predictable usage pattern? You can automatically scale up and down your deployment on a schedule to achieve optimal performance and reduce operating costs.
In this article we show you how to use the Elastic Cloud API to change how many Enterprise Search nodes you’re running. We call these APIs from a cron job to achieve hands-free, time-triggered autoscaling.
And for a comprehensive scaling strategy, you can combine the time-based scaling technique presented here with Elastic Cloud's recently released autoscaling capabilities. With a few simple clicks in the Elastic Cloud UI, you can automatically scale your Elasticsearch and ML nodes as your data grows.
The problem: Handling predictable traffic spikes
Some of our users have predictable search spikes, like during business hours, or a spike between 9:00am and 10:00am on weekdays, or the second and fourth Friday of every month. During these times, they might need many more Enterprise Search and Elasticsearch nodes to handle the load.
Autoscaling algorithms typically rely on events such as high CPU, high memory, or disk consumption to increase a deployment to meet the increased demand.
In the case of predictable, high spikes in traffic, so many visitors come online so suddenly that we cannot wait for a metric like high CPU before deploying new nodes. We need new nodes ready to take traffic at the start of the spike.
Scaling Enterprise Search on Elastic Cloud
Elastic Cloud offers a robust REST API to configure your deployments.
Resizing an Enterprise Search deployment via API using curl
follows this general pattern:
export DEPLOYMENT_ID=bf4d13dcdc9340f5ac... # Your Cloud deployment ID from the Cloud Deployments page export ECE_API_KEY=VlU4MDFIY0JxVld3M... # Generate an API key under Cloud, Features, API Keys curl -k -X PUT -H "Authorization: ApiKey $ECE_API_KEY" https://cloud.elastic.co/api/v1/deployments/$DEPLOYMENT_ID -H 'content-type: application/json' -d '{ ... plan template changes payload ... }'
To easily determine the plan changes payload, use the Elastic Cloud Deployments UI to prepare the changes you want to make to your cluster. In the Edit Deployment screen, change the number of nodes and size of each node:
Select the Equivalent API request link below the Save button to copy the corresponding JSON plan template:
The Elastic Cloud API does not offer a JSON attribute such as node_count
or node_size
to set the number of Enterprise Search nodes. Instead, the API accepts a value for the total memory of the Enterprise Search deployment. Each node has a fixed size, for example 8GB
, configurable as a separate parameter in your Deployment plan. Elastic Cloud computes how many nodes you will require to meet your specified total memory.
For example, here is a snippet of an Enterprise Search deployment plan being resized to 4 nodes. Each node is 8GB
.
"enterprise_search": [ { ... "plan": { "cluster_topology": [ { ... "size": { "value": 32768, <------------------------- "resource": "memory" }
For comparison, here is the same deployment resized to 5 nodes:
"enterprise_search": [ { ... "plan": { "cluster_topology": [ { ... "size": { "value": 40960, <------------------------ "resource": "memory" }
For our example, record the equivalent API request from the Cloud UI for resizing an Enterprise Search deployment to 4 Enterprise Search nodes. Then record the equivalent API request for resizing the deployment to 2 nodes.
Test the deployment changes from a command line using curl
following the pattern above.
Scaling on a schedule
Now that you have the API calls necessary to scale up and down your deployment, invoke the API calls at the necessary times.
One simple way to run the API calls on a schedule could be to use cron
on a Linux machine.
For example, run cron
and edit a crontab
file to run the curl
command to scale up at 8:00 and scale down at 11:00:
sudo service crond start sudo crontab -e 0 8 * * * curl -k -X PUT -H … 0 11 * * * curl -k -X PUT -H ...
The curl
command headers will need your ECE_API_KEY
generated earlier. Make sure to use a secure token manager to store this key or put the key into a file that has restricted read access. If your crontab
file is exposed, you don’t want your Elastic Cloud API credentials to be leaked.
The above cron example follows this format:
0 8 * * * YOURCMD 0 – 0th Minute 0 – 8AM *– Every day *– Every month *– Every day of the week
Conclusion
We’ve shown how to use the Elastic Cloud API to scale up and down your Enterprise Search deployment at specific times.
Next up: Want to go further and scale your Elasticsearch or ML nodes automatically as your data grows? With autoscaling on Elastic Cloud, in a few clicks you can ensure your Enterprise Search deployment will scale to meet all your future data storage needs. You can try it out for yourself with a free, 14-day trial of Elastic Cloud.