Skip to content

Instantly share code, notes, and snippets.

@oubiwann
Created October 14, 2012 01:50
Show Gist options
  • Save oubiwann/3886959 to your computer and use it in GitHub Desktop.
Save oubiwann/3886959 to your computer and use it in GitHub Desktop.
Native LoadBalancing for Twisted Apps
from twisted.web import static, server
from twisted.application import service, internet
application = service.Application("Demo Web Server")
web = server.Site('/home/oubiwann/public_html')
service = internet.TCPServer(7001, web)
service.setServiceParent(application)
from twisted.application import service
from txlb import manager
from txlb.model import HostMapper
from txlb.schedulers import leastc
from txlb.application.service import LoadBalancedService
proxyServices = [
HostMapper(proxy='127.0.0.1:8080', lbType=leastc, host='host1',
address='127.0.0.1:7001'),
HostMapper(proxy='127.0.0.1:8080', lbType=leastc, host='host2',
address='127.0.0.1:7002'),
HostMapper(proxy='127.0.0.1:8080', lbType=leastc, host='host3',
address='127.0.0.1:7003'),
]
application = service.Application('Demo LB Service')
pm = manager.proxyManagerFactory(proxyServices)
lbs = LoadBalancedService(pm)
lbs.setServiceParent(application)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment