Friday, December 28, 2018

Software complexity address - tests/comments/QA/DB/code

The complexity goes somewhere. It's either into lots tests, or it's into something like shuttle style with lots of comments, or it's into a huge QA department, or it's into the type system / DB schema. It could even be going into the org structure! But something, somewhere is handling the complexity and it is doing so as a partial function to the economic importance of the software to the stakeholders of the software.

Wednesday, April 4, 2018

understand extra pair of trap and wait



https://stackoverflow.com/questions/49489948/why-an-extra-pair-of-trap-and-wait

============
test.sh
============
#!/bin/bash

_term() {
  echo "SHELL: Caught SIGTERM signal, propagating to the child"
  kill -TERM "$child" 2>/dev/null
}

trap _term SIGTERM

python3 test.py &
child=$!
wait "$child"
exit_status=$?
trap - SIGTERM
wait "$child"

if test ${exit_status} -eq 0; then
  echo "SHELL: Task finished.";
else
  echo "SHELL: Task failed.";
  exit ${exit_status}
fi


============
test.py
============
import time
import sys


import signal
import time

class GracefulKiller:
  kill_now = False
  def __init__(self):
    signal.signal(signal.SIGINT, self.exit_gracefully)
    signal.signal(signal.SIGTERM, self.exit_gracefully)

  def exit_gracefully(self,signum, frame):
    self.kill_now = True

if __name__ == '__main__':
  killer = GracefulKiller()
  while True:
    print("== going to sleep ==")
    time.sleep(30)
    print("== woken up ==")
    if killer.kill_now:
      break

  print("End of the program. I was killed gracefully :)")

--
Rahul Gupta




Thursday, February 15, 2018

What is ELB black hole problem?

AWS Elastic Load Balancer Black Hole

Problem -
Load balancer acts as a proxy between client and server ensuring requests from multiple clients get fairly distributed to cluster of servers.
Whenever a server deregisters from ELB, ELB continues to forward it the requests to a black hole i.e. a place which no longer exists.
Clients many a times don't realize that their requests are getting lost if these requests are more of one way traffic without any response expectation.

Solution -
Once in a while, clients should send a request expecting a response esp. over a long lived connection. That way, if the actual server is down, client will know.
Instead of deregistering a server, shutting it down is better because that way, the server connections to the ELB are closed and the upstream clients are notified appropriately that what they were talking to is no longer available.