Skip to main content

Programming Epiphany

I hate doing tasks that are repetitive or that someone else should do but its a waste of my time. Earlier we used to store user and customer data on LDAP and there were all sort of BS requests from marketing like tell me "all customers that are on PlanY and are buy domain with >5 users".  Problem is there were 40 ldaps and each one of these would require writing a custom script. Teaching other programmers ldap was not reasonable.  One of my goals at my employer is to "Empower people to retrieve information themselves". I don’t want to be bottleneck in their chain of thoughts and they need not be bottleneck in what I want to do. I don’t want to involve humans if at all possible.

So when we migrated to Ldap->Mysql, first thing I did was consolidated 40 ldaps per data centre to 4 Mysql server per datacentre.  I could have consolidated to 1 also but that would suffer from noisy neighbour issue.  Problem is that there are 3 Data centres so in total 12 mysql servers.  Still people would come to me for data just because I architected Ldap2Mysql.  People need to understand that my job is to "Empower people by writing tools/frameworks so that they can do their job themselves".

Two weeks back I got a custom request where someone wanted all emails of all users in 11 thousand customer accounts. I was like its BS either I can give you all or I can give you none. It would waste 2-3 hours of my time if I had to do it. I even tried creating a SQL query with 11K domains in IN clause and   Mysql would run it by python program to query 12 Mysql servers would bomb due to command line argument limitation.  So I refused to do it and it was given to someone else in the team who would split the list into 1K domains and combine the CSV.  But then I realized the issue for me was not splitting the result into 1K domains and constructing IN clause as that I can do programatically or in excel in 10-20 min. Problem to me was that my program was generating output as python tuple format so who would combine the 11 log files and do all that data scrubbing to generate final CSV.

Today again the developer attached to internal apps team was asked to produce a list of all admin users of all customers who want to recieve our newsletter.  The developer sent email to me that I should do it. I was like wth its not my job, the marketing team should hire someone with SQL skills to do it and I can give him pointers on how to retrieve information.  Problem is that today one more developer whom I can delegate was on medical leave so the thing came back to me. I had to go to my son's school in 20 min so I was in time crunch. I thought I have everything, I have a program that given a template query would execute it on all Mysql databases and print it in tuple format and this is a common requirement that they want it in CSV so why not change program to do both.

within 5 min I changed code like this
        for row in pc_db_conn.execute(query):
            print row
to
        for row in pc_db_conn.execute(query):
            print row
            #I know this is BS and I should use csv module but this is internal shit
            csv_file.write(','.join(['"'+str(s)+'"' for s in row])) 
            csv_file.write('\n')

and tada the job was done. Now it seems for this kind of queries I eliminated the need for that developer. So I eliminated a human for one more task and this gave me a programming epiphany for the day.

I was whole day battling with newrelic, appdynamics and vivid cortex to find performance anomalies but this 5 min change gave me more joy than other things I found using those tools.

This blog post is dedicated to a fellow developer who once asked me how do I came up with all these ideas. So just trying to describe the thought process of eliminating myself from doing grunt work forces me to think these things.



Comments

Popular posts from this blog

Killing a particular Tomcat thread

Update: This JSP does not work on a thread that is inside some native code.  On many occasions I had a thread stuck in JNI code and it wont work. Also in some cases thread.stop can cause jvm to hang. According to javadocs " This method is inherently unsafe. Stopping a thread with Thread.stop causes it to unlock all of the monitors that it has locked". I have used it only in some rare occasions where I wanted to avoid a system shutdown and in some cases we ended up doing system shutdown as jvm was hung so I had a 70-80% success with it.   -------------------------------------------------------------------------------------------------------------------------- We had an interesting requirement. A tomcat thread that was spawned from an ExecutorService ThreadPool had gone Rogue and was causing lots of disk churning issues. We cant bring down the production server as that would involve downtime. Killing this thread was harmless but how to kill it, t

Adding Jitter to cache layer

Thundering herd is an issue common to webapp that rely on heavy caching where if lots of items expire at the same time due to a server restart or temporal event, then suddenly lots of calls will go to database at same time. This can even bring down the database in extreme cases. I wont go into much detail but the app need to do two things solve this issue. 1) Add consistent hashing to cache layer : This way when a memcache server is added/removed from the pool, entire cache is not invalidated.  We use memcahe from both python and Java layer and I still have to find a consistent caching solution that is portable across both languages. hash_ring and spymemcached both use different points for server so need to read/test more. 2) Add a jitter to cache or randomise the expiry time: We expire long term cache  records every 8 hours after that key was added and short term cache expiry is 2 hours. As our customers usually comes to work in morning and access the cloud file server it can happe

Preparing for an interview after being employed 11 years at a startup

I would say I didn't prepared a hell lot but  I did 2 hours in night every day and every weekend around 8 hours for 2-3 months. I did 20-30 leetcode medium problems from this list https://leetcode.com/explore/interview/card/top-interview-questions-medium/.  I watched the first 12 videos of Lecture Videos | Introduction to Algorithms | Electrical Engineering and Computer Science | MIT OpenCourseWare I did this course https://www.educative.io/courses/grokking-the-system-design-interview I researched on topics from https://www.educative.io/courses/java-multithreading-for-senior-engineering-interviews and leetcode had around 10 multithreading questions so I did those I watched some 10-20 videos from this channel https://www.youtube.com/channel/UCn1XnDWhsLS5URXTi5wtFTA