Search

13.4.4. Scaling Action Hooks

download PDF
Automatic scaling is controlled by the haproxy_ctld daemon. The haproxy_ctld.rb script, which changes the thresholds and algorithms used to control scale up and down behavior, can be customized for use as an action hook in scalable applications.

Procedure 13.3. To Customize Automatic Scaling for an Application:

  1. Use SSH to connect to a scalable application and consult the generic ~/haproxy/usr/bin/haproxy_ctld.rb script for detailed usage information.
  2. Copy the file to the Git repository of the application in the App_Name/.openshift/action_hooks/ directory.
  3. Ensure the file is executable:
    # chmod +x App_Name/.openshift/action_hooks/haproxy_ctld.rb
  4. Edit the file to the desired specifications.
  5. Deploy the changes. To ensure that the changes take effect immediately, the HAProxy cartridge restarts automatically during deployment if the haproxy_ctld.rb action hook is detected.

Example 13.2. Scaling Up Based on Memory Usage

To enable auto-scaling based on memory usage, edit the ~/haproxy/usr/bin/haproxy_ctld.rb script by specifying the following parameters.
...
# Scale up when any gear is using 400M or more memory.
mem_scale_up = 419430400

# Scale down when any gear is using 300M or less memory
mem_scale_down = 314572800

# min_gears - Once this number of gears is met, don't try to scale down any lower
min_gears = 2

gear_list['web'].each do |uuid, array|
 mem_usage = `ssh -i ~/.openshift_ssh/id_rsa #{uuid}@#{array['dns']} 'oo-cgroup-read memory.memsw.usage_in_bytes'`.to_i
 if mem_usage >= mem_scale_up
   @log.error("memory usage (#{mem_usage}) on #{array['dns']} is above threshold(#{mem_scale_up}), adding new gear")
   self.add_gear
 end
end
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.