I went through the OWIN hosting tutorial and got things up and running, but when I change set the InstanceCount to -1, it seems like every instance of the service is trying to listen on port 80 in the OpenAync method when it calls WebApp.Start.
I assumed Service Fabric would manage ports dynamically as it spun up services to avoid port collisions, but it does not seem like this is happening.
An InstanceCount of -1 only makes sense for stateless services running on a multi-machine cluster. In that case, each node is running on its own machine so you don't have port conflicts and you can configure the Azure load balancer to round-robin traffic through the machines hosting those instances.
On a local cluster, all of the nodes are on the same machine, so if they try to share a common HTTP prefix, they will indeed conflict. To avoid this, just set InstanceCount for your stateless services to 1 for local deployments.
All of this is only required in cases where you want to communicate with your services using a predefined port. If you don't specify a port in the service manifest, the platform will automatically assign one when the service starts up. However, it is then incumbent on clients to discover your endpoints dynamically using the platform's name resolution APIs, which is often not desirable.
As a result, the common pattern is to have a stateless front-end to your application listening on a predefined port, which then performs name resolution to relay requests on to other services. Those second-level services can be listening on a port dynamically assigned by the platform.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With