Permalink
Fetching contributors…
Cannot retrieve contributors at this time
80 lines (54 sloc) 3.01 KB

Clients

Clients will commonly issue /check/... requests via HEAD. freno responds by setting an appropriate HTTP status code.

While GET method is also supported, the response for HEAD requests is shorter and involves less computation by freno. GET is more useful to humans.

Clients can be expected to issue many requests per second. freno is lightweight in resources. It should be just fine to hit freno hundreds of times per second. It depends on your hardware and resources, of course.

freno probes backend stores continuously and independently of client requests. Client requests merely pick up on the latest metrics collected by freno, and do not synchronously wait on servers to be polled.

It makes sense to hit freno in the whereabouts of the granularity one is looking at. If your client is to throttle on a 1000ms replication lag, checking freno 200 times per sec may be overdoing it. However if you wish to keep your clients naive and without caching this should be fine.

It is also possible to ask freno to write metrics to memcache, in which case clients can read metrics directly using their favorite memcache client.

Usage samples

Ruby

freno-client is our official Ruby client for freno. It is open sourced and available as a Ruby Gem.

require "freno/client"

FRENO_URL = "http://my.freno.com:9777"
faraday   = Faraday.new(FRENO_URL)
freno     = Freno::Client.new(faraday)

freno.check?(app: :my_app, store_name: :my_cluster)
# => true

freno.replication_delay(app: :my_app, store_name: :my_cluster)
# => 0.125

pt-archiver / perl

pt-archiver is probably the most popular tool for archiving table data. pt-archiver can use freno with a plugin. A plugin is available on FrenoThrottler.pm. To make it usable, you will need to:

  • Let the plugin know where to find freno and which cluster to use (see sample code in comment in plugin file)

  • Deploy the plugin. Sample puppet deployment would look something like:

    file { '/usr/share/perl5/FrenoThrottler.pm':
        ensure => file,
        owner  => 'root',
        group  => 'root',
        mode   => '0755',
        source => 'puppet:///modules/percona/usr/share/perl5/FrenoThrottler.pm';
    }
    

    This assumes /usr/share/perl5 is in your @INC path (run perl -e 'print "@INC"' to confirm).

shell

if curl -s -I http://my.freno.com:9777/check/myscript/mysql/main7 | grep -q "200 OK" ; then
  echo "Good to go, do some writes"
else
  echo "Need to throttle; please refrain from writes"
fi

Go

import "net/http"

const frenoUrl = "http://my.freno.com:9777/check/my-go-app/mysql/main7"

func CheckFreno() (canWrite bool, err error) {
	resp, err := http.Head(frenoUrl)
	if err != nil {
		return false, err
	}
	return resp.StatusCode == http.StatusOK, nil
}