[Twisted-Python] Bring multi service up gradually
![](https://secure.gravatar.com/avatar/22736b718bada1e89bb3c2457889a29e.jpg?s=120&d=mm&r=g)
Hi. I have got a number of services that am bringing together at startup. In the past, I have added them to a parent and started them up all at one time. But now I am incorporating a service (the main service) that may be available from more than one address and I want to connect with one of these addresses first before starting the other services. What I am seeking is some general advice on this since I want the startup to be as efficient as possible. I was thinking that quickly testing the addresses first, before starting any twisted service might help increase the odds of a quick startup. But if this fails, I will still need to iterate with a backoff through each address to connect the main service, then add the other services when the main service is running. Many thanks. Regards, David
![](https://secure.gravatar.com/avatar/96a6fa70caad11789ce45b7096860447.jpg?s=120&d=mm&r=g)
I don't think there is a way to insure you will get the ports you want. Why bother testing if the port is available before hand? In between the port being tested and the application using it someone can sneak in and take it. I have built a twistd app that uses 5 different services and find the good old way is the easiest and fastest: just bring them up. Chaz
![](https://secure.gravatar.com/avatar/22736b718bada1e89bb3c2457889a29e.jpg?s=120&d=mm&r=g)
Chaz. wrote:
I don't think there is a way to insure you will get the ports you want. Why bother testing if the port is available before hand? In between the port being tested and the application using it someone can sneak in and take it.
Hi Chaz. Thank you for your reply. The reason for the test is that I don't want the other services to start at all if a connection cannot be found to run the main service. I was thinking of writing a simple tester using socket module to determine which addresses are alive first. When it finds one it stops so in my logic I give this address to my ListenTCP/SSL and attempt to start the main service. I don't expect the address list to be large. This way no time is lost with the client running through a long backoff cycle on an address that may not be alive only to have to stop it and try a another until one is possibly found. I am not aware of something in twisted that evaluates addresses like this as part of a startup solution. In any case, if I see that an address in the list is available, then I would start my main service using it. When a connection is made to the main address, then I want to start the remaining services since they are useless without the main service. Regards, David
![](https://secure.gravatar.com/avatar/96a6fa70caad11789ce45b7096860447.jpg?s=120&d=mm&r=g)
I would know how to do it in C, but I am no twisted expert. The idea would be to open the socket and hand it off to the service to use. I am sure there is a way to do it in Twisted (opening a port and using it in a service). What you don't want to do is just "test" the port (opening it and closing it). Once you have it opened, you need to keep it open. Chaz David Pratt wrote:
Chaz. wrote:
I don't think there is a way to insure you will get the ports you want. Why bother testing if the port is available before hand? In between the port being tested and the application using it someone can sneak in and take it.
Hi Chaz. Thank you for your reply. The reason for the test is that I don't want the other services to start at all if a connection cannot be found to run the main service. I was thinking of writing a simple tester using socket module to determine which addresses are alive first. When it finds one it stops so in my logic I give this address to my ListenTCP/SSL and attempt to start the main service.
I don't expect the address list to be large. This way no time is lost with the client running through a long backoff cycle on an address that may not be alive only to have to stop it and try a another until one is possibly found.
I am not aware of something in twisted that evaluates addresses like this as part of a startup solution. In any case, if I see that an address in the list is available, then I would start my main service using it. When a connection is made to the main address, then I want to start the remaining services since they are useless without the main service.
Regards, David
![](https://secure.gravatar.com/avatar/22736b718bada1e89bb3c2457889a29e.jpg?s=120&d=mm&r=g)
Hi Chaz. Yes, passing the connection from a test that iterates through addresses would be the best solution. I still have authentication that is handled by twisted upon connection but the first priority is finding something is on the other end so I've got a viable service. If there is a way to do something like this directly in twisted I'm hoping for some direction. Many thanks. Regards, David Chaz. wrote:
I would know how to do it in C, but I am no twisted expert. The idea would be to open the socket and hand it off to the service to use. I am sure there is a way to do it in Twisted (opening a port and using it in a service).
What you don't want to do is just "test" the port (opening it and closing it). Once you have it opened, you need to keep it open.
Chaz
David Pratt wrote:
Chaz. wrote:
I don't think there is a way to insure you will get the ports you want. Why bother testing if the port is available before hand? In between the port being tested and the application using it someone can sneak in and take it. Hi Chaz. Thank you for your reply. The reason for the test is that I don't want the other services to start at all if a connection cannot be found to run the main service. I was thinking of writing a simple tester using socket module to determine which addresses are alive first. When it finds one it stops so in my logic I give this address to my ListenTCP/SSL and attempt to start the main service.
I don't expect the address list to be large. This way no time is lost with the client running through a long backoff cycle on an address that may not be alive only to have to stop it and try a another until one is possibly found.
I am not aware of something in twisted that evaluates addresses like this as part of a startup solution. In any case, if I see that an address in the list is available, then I would start my main service using it. When a connection is made to the main address, then I want to start the remaining services since they are useless without the main service.
Regards, David
![](https://secure.gravatar.com/avatar/dc1aa795ec44b3524526e654111caa97.jpg?s=120&d=mm&r=g)
Why not simply start the additional services from the startFactory-method of your mainservice' protocol factory? i,e,: class MainServiceFac(ServerFactory): def startFactory(self): <possibly call parent's startFactory> reactor.listenTCP(.... subservice 1) reactor.listenTCP(.... subservice 2).... On Fri, 2006-06-16 at 10:39 -0300, David Pratt wrote:
Chaz. wrote:
I don't think there is a way to insure you will get the ports you want. Why bother testing if the port is available before hand? In between the port being tested and the application using it someone can sneak in and take it.
Hi Chaz. Thank you for your reply. The reason for the test is that I don't want the other services to start at all if a connection cannot be found to run the main service. I was thinking of writing a simple tester using socket module to determine which addresses are alive first. When it finds one it stops so in my logic I give this address to my ListenTCP/SSL and attempt to start the main service.
I don't expect the address list to be large. This way no time is lost with the client running through a long backoff cycle on an address that may not be alive only to have to stop it and try a another until one is possibly found.
I am not aware of something in twisted that evaluates addresses like this as part of a startup solution. In any case, if I see that an address in the list is available, then I would start my main service using it. When a connection is made to the main address, then I want to start the remaining services since they are useless without the main service.
Regards, David
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
![](https://secure.gravatar.com/avatar/22736b718bada1e89bb3c2457889a29e.jpg?s=120&d=mm&r=g)
Hi Thomas. Thank you for your reply. Yes, this might be a plan for starting services. I'll look at how something like this could work with my config since I am not using twisted app in this case but integrated with another daemon service. Many thanks. Regards, David Thomas Jacob wrote:
Why not simply start the additional services from the startFactory-method of your mainservice' protocol factory?
i,e,:
class MainServiceFac(ServerFactory): def startFactory(self): <possibly call parent's startFactory> reactor.listenTCP(.... subservice 1) reactor.listenTCP(.... subservice 2)....
On Fri, 2006-06-16 at 10:39 -0300, David Pratt wrote:
Chaz. wrote:
I don't think there is a way to insure you will get the ports you want. Why bother testing if the port is available before hand? In between the port being tested and the application using it someone can sneak in and take it. Hi Chaz. Thank you for your reply. The reason for the test is that I don't want the other services to start at all if a connection cannot be found to run the main service. I was thinking of writing a simple tester using socket module to determine which addresses are alive first. When it finds one it stops so in my logic I give this address to my ListenTCP/SSL and attempt to start the main service.
I don't expect the address list to be large. This way no time is lost with the client running through a long backoff cycle on an address that may not be alive only to have to stop it and try a another until one is possibly found.
I am not aware of something in twisted that evaluates addresses like this as part of a startup solution. In any case, if I see that an address in the list is available, then I would start my main service using it. When a connection is made to the main address, then I want to start the remaining services since they are useless without the main service.
Regards, David
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
------------------------------------------------------------------------
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
participants (3)
-
Chaz.
-
David Pratt
-
Thomas Jacob