This library is a strategy for libcluster
for connecting nodes in Google App Engine. If you're unfamiliar with libcluster
, please read the documentation.
This library makes the assumption that the elixir application is using Distillery releases.
Add :libcluster_gae
to your project's mix dependencies.
def deps do
[
{:libcluster_gae, "~> 0.1"}
]
end
Clustering will only apply to nodes that are configured to receive HTTP traffic in App Engine are currently running and belong to the same service. If this doesn't fit your deployment strategy, please open a Github issue describing your deployment configuration.
Before clustering can work, enable the App Engine Admin API for your application's Google Cloud Project. Follow the guide on enabling APIs.
To cluster an application running in Google App Engine, define a topology for libcluster
.
# config.exs
config :libcluster,
topologies: [
my_app: [
strategy: Cluster.Strategy.GoogleAppEngine
]
]
Make sure a cluster supervisor is part of your application.
defmodule MyApp.App do
use Application
def start(_type, _args) do
topologies = Application.get_env(:libcluster, :topologies)
children = [
{Cluster.Supervisor, [topologies, [name: MyApp.ClusterSupervisor]]},
# ...
]
Supervisor.start_link(children, strategy: :one_for_one, name: MyApp.Supervisor)
end
end
Update your release's vm.args
file to include the following lines.
## Name of the node
-name <%= release_name%>@${GAE_INSTANCE}.c.${GOOGLE_CLOUD_PROJECT}.internal
## Limit distributed erlang ports to a single port
-kernel inet_dist_listen_min 9999
-kernel inet_dist_listen_max 9999
Update the app.yaml
configuration file for Google App Engine.
env_variables:
REPLACE_OS_VARS: true
network:
forwarded_ports:
# epmd
- 4369
# erlang distribution
- 9999
Now run gcloud app deploy
and enjoy clustering on GAE!