问题
I am working on a POC with azure service fabric. Deployed my service in a local cluster and it's working fine with default settings in Local.xml.
The moment I change the instance count it's throwing following exception. Where is the option to change the instance count? Basically i am trying to run my service on two nodes now. It's working fine when it is the default value that is 1.
InnerException: HResult=-2146233088 Message=Error -4091 EADDRINUSE address already in use Source=Microsoft.AspNetCore.Server.Kestrel StatusCode=-4091
My local.xml is copied here
<Parameters>
<Parameter Name="Product_InstanceCount" Value="2" />
</Parameters>
Any help really appreciated.
Thanks
回答1:
According to the official Microsoft documentation , you need to ensure that only one instance of the service is running when you deploy to a local cluster.Otherwise you will run into conflicts with multiple processes listening to same port .You can set multiple instances when you deploy to Azure.
Refer the documentation :- https://azure.microsoft.com/en-us/documentation/articles/service-fabric-add-a-web-frontend/
回答2:
When you are using local sf cluster and if you have fixed the service endpoint port, use only one instance. For example:
Service.Endpoint uses port 8090. This is defined in ServiceManifest.xml. In a local cluster actually everything just runs on one node i.e. your development machine. If you try to create 2 instances of same service with hard defined port, then you will get Port already in use error.
Try changing to one instance or move it to actual Azure cluster or remove hard coded port numbers.
回答3:
I have not experienced this issue.
You can change the instance count programatically using the fabric client:
var fabricClient = new FabricClient();
var instanceCount = 3;
var services = await fabricClient.QueryManager.GetServiceListAsync(new Uri("fabric:/MyMicroServiceApp"));
var service = services.FirstOrDefault(e => e.ServiceName.AbsolutePath.Contains("MyService"));
var updateDescription = new StatelessServiceUpdateDescription();
updateDescription.InstanceCount = instanceCount;
await fabricClient.ServiceManager.UpdateServiceAsync(new Uri(service.ServiceName.AbsoluteUri), updateDescription);
I used this to develop a proof of concept to increase the number of worker processes depending on the size of a queue. As soon as you change the instance count of a service, the Service Fabric framework will automatically deploy / remove an instance of the service to / from a node.
回答4:
If you are running some type of ASP.Net or Owin hosted service. You have to use an instance count of -1. This will setup one instance on each node. With an instance count of 2, you get 2 instances, which may or may not be on the same node.
回答5:
We have a similar problem and solved it with build scripts. You can either replace the ServiceManififest via a build script or use Tokenizer to replace the port value.
Locally you can create and install the updated/adjsuted package files and deploy them with DeployFabricApplciation and test against it that way.
来源:https://stackoverflow.com/questions/38121146/azure-service-fabric-instance-count