Awesome
TileStrata Balancer
An elastic metatile-aware load balancer to sit in front of multiple TileStrata servers (must be >= 2.0.0).
$ npm install tilestrata-balancer -g
$ tilestrata-balancer \
--hostname=127.0.0.1 \ # bind address
--port=8080 \ # for connections from the outside world
--private-port=8081 \ # for connections from tilestrata tile servers
--check-interval=5000 \ # how often to ping child nodes
--unhealthy-count=1 # consecutive unhealty pings needed to determine a host is unhealthy
Configuration
First and foremost, whatever --private-port
is set to needs to not be accessible to the outside world. This is crucial so that outside connections can't maliciously insert a random node into the pool.
On the servers upstream, use the balancer
option to set where to find the load balancer. When TileStrata starts up, it will check-in with the load balancer, informing it that its ready to be routed to. After that, the balancer will periodically check /health
to ensure the node is healthy.
var strata = tilestrata({
balancer: {
/* the port should match --private-port */
host: '192.168.0.1:8081',
/* the magnitude is relative to other servers (default: 1) */
node_weight: 3
}
});
If using metatiles, set the metatile
option on the layer to have it recognized by the balancer. Note: this will likely be redundant with plugin settings.
strata.layer('mylayer', {metatile, 4})
.use(mapnik({metatile: 4, /* ... */}))
Additional Notes
One cool thing to note is that TileStrata Balancer allows layers to be non-homogenously spread about your cluster. The balancer keeps track of what layers exist on each host. This property is great if you have multiple maps that are tough to squeeze on a single server.
The Contract
- TileStrata should start up and send periodic POSTs to
/nodes
until it receives a201 Created
. The request body should contain a uniqueid
,node_weight
and alayers
array with various parameters about each (minZoom
,maxZoom
,metatile
). The successful response body (JSON) will contain a"token"
property that is later sent as theX-TileStrataBalancer-Token
header on health checks. - TileStrata Balancer will send periodic requests to
/health
on the TileStrata node to ensure it's healthy. If unhealthy, the node is dropped from the pool. TileStrata should detect the lack of incoming health checks from the balancer (indicated byX-TileStrataBalancer-Token
) and attempt to re-register (1).- If TileStrata is shutting down, it should call
DELETE /nodes/:id
on the balancer.
- If TileStrata is shutting down, it should call
License
Copyright © 2015 Natural Atlas, Inc. & Contributors
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.