Permalink
Browse files

added transaction server load balancing and redundancy. Note this cod…

…e has not ben testing at all
  • Loading branch information...
1 parent f083079 commit 8943149aa899981f9fde9b5db32747a476be5b21 @alimjiwa alimjiwa committed Apr 2, 2012
Showing with 25 additions and 5 deletions.
  1. +7 −2 deployment/fabfile.py
  2. +10 −0 sps/web/app.py
  3. +8 −3 sps/web/transaction_interface.py
View
@@ -28,7 +28,7 @@
env.roledefs = {
'db': ['a01'],
'web': ['a02', 'a04', 'a06'],
- 'transaction': ['a03'],
+ 'transaction': ['a03', 'a05'],
'tsung': ['a10', 'a11', 'a09'],
'vm': ['vagrant@127.0.0.1:2222'],
'master': ['a09'],
@@ -86,9 +86,14 @@ def update_config_file(quote_client='sps.quotes.client.RandomQuoteClient'):
"""
Updates the remote config file with the local one
"""
+
+ trans_serv_index = env.roledefs['web'].index(env.host) % len(env.roledefs['transaction'])
+ backup_trans_serv_index = (env.roledefs['web'].index(env.host)+1) %len(env.roledefs['transaction'])
+
# Use fabfile's predefined server names
context = {
- "transaction_server": _machine_num(env.roledefs['transaction'][0]),
+ "transaction_server": _machine_num(env.roledefs['transaction'][trans_serv_index]),
+ "backup_transaction_server": _machine_num(env.roledefs['transaction'][backup_trans_serv_index]),
"database_server": _machine_num(env.roledefs['db'][0]),
"quote_client": quote_client,
}
View
@@ -47,6 +47,16 @@ def hello():
config.TRANSACTION_SERVER_PORT,
trans_server_message)
+ if response == False:
+ #resend to backup server
+
+ response = transaction_interface.send(
+ config.BACKUP_TRANSACTION_SERVER_HOST,
+ config.TRANSACTION_SERVER_PORT,
+ trans_server_message)
+
+
+
log.info('Received from transaction server: %s', repr(response))
# Try to parse XML response and determine HTTP code
@@ -5,10 +5,15 @@
def send(HOST, PORT, message):
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- s.connect((HOST, PORT))
+ try:
+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ s.connect((HOST, PORT))
+
+ s.sendall(message + '\n')
+ except socket.error:
+ return False
+
- s.sendall(message + '\n')
# Read an entire line of variable length
confirmation_msg = s.makefile().readline()

0 comments on commit 8943149

Please sign in to comment.