The example below applies it on the Host header. HAProxy can apply the hash to a specific HTTP header field. Hash-type consistent Hash on an HTTP header The configuration below tells HAProxy to apply the hash to the query string parameter named ‘id’ (IE: /image.php?width=512&id=12&height=256) backend bk_static This applies well in cases where the client can forge itself the URL and all the parameters may be randomly ordered. We may want to hash only on a particular query string parameter. That said, in some cases (API, etc…), hashing the whole URL is not enough. Hash-type consistent Query string parameter hash In some cases, the query string may contain some variables in the query string, which means we must include the query string in the hash: backend bk_static Hash-type consistent Hashing the whole URL, including the query string In the example below, HAProxy hashes the URL path, which is from the first slash ‘/’ character up to the question mark ‘?’: backend bk_static With this load-balancing algorithm, we guarantee that a single URL will always hit the same Varnish server. HAProxy can hash the URL to pick up a server. Now, let’s focus on the magic we can add in the bk_static server farm. That’s why you’ll see a lot of hash-type consistent directives in the configuration samples below. Fortunately, HAProxy allows ‘consistent’ hashing, which means that only the traffic related to the change will be impacted. This may lead to a negative impact on the response time of the application (during a short period of time). If any of the parameters above changes, the whole hash computation also changes. The following parameters are taken into account when computing a hash algorithm: So a few pieces of information here (nonexhaustive, it would deserve a long blog article) which will be useful for people wanting to understand what happens deep inside HAProxy. Later in this article, we’ll heavily use the hash-based load balancing algorithms from HAProxy. Haproxy & Hash Based Load Balancing Algorithm The configuration above creates 2 named acls ‘ static_domain‘ and ‘ static_content‘ which are used by the used_backend rule to route the traffic to varnish servers. Use_backend bk_static if static_domain or static_content frontend ft_publicĪcl static_domain req.hdr_beg(Host) -i static. The varnish servers will stand in the bk_static farm. It matches the rules above to do traffic splitting. The configuration snippet below should be integrated into the HAProxy frontend. Static content can match any of the rules aboveĪnything which is not static is considered dynamic Static content files extensions are ‘.jpg’ ‘.png’ ‘.gif’ ‘.css’ ‘.js’ Static content is hosted on domain names starting with ‘static.’ and ‘images.’ A fetch is a directive that instructs HAProxy where to get content from.Įnough theory, let’s make a practical example: splitting static and dynamic traffic using the following rules: Then HAProxy routes traffic to a backend (server farm) where the load-balancing algorithm is used to choose a server.Ī frontend can point to multiple backends and the choice of a backend is made through acls and use_backend rules. As a quick introduction for readers who are not familiar with HAProxy, let’s explain how it works.Ĭlients will get connected to HAProxy through a Frontend. This has been covered many times on this blog. This will also improve your application response time. The main purpose of the examples delivered here is to optimize the resources on the cache, mainly its memory, in order to improve the HIT rate. The main purpose of this article is to show how HAProxy can be used to aggregate Varnish servers' memory storage in some kind of “JBOD” mode (like the “ Just a Bunch Of Disks“). HAProxy stands in front of your cache server for some good reasons: That said, cache servers, which deliver most of the time the static content from your web applications, may require some specific load balancing algorithms. HAProxy supports many load balancing algorithms, which may be used in many different types of use cases.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |