13.4.4. Scaling Action Hooks

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")