Posts

Showing posts from 2016

Performance boost for GPU

I recently surfaced couple of ways to speed up GPU based application. I was experimenting with art transformation of images on a P2 class AWS machines. The process was taking anytime between 10 to 16 seconds, with an average of around 14 seconds. I was exploring, if time can be further optimized.
A brief chat with AWS resolved it for me. The AWS support guy asked me to set up my P2 per https://aws.amazon.com/blogs/aws/new-p2-instance-type-for-amazon-ec2-up-to-16-gpus/
I had done almost everything confirming to link above, except last 4 statements. Turns out, these commands configure some cool performance configurations.
Nvidia-smi (https://developer.nvidia.com/nvidia-system-management-interface) is a CLI for Nvidia GPU devices. As AWS P2 class server contain Nvidia Tesla K80 devices, I can use nvidia-smi to see and set options.
nvidia-smi -pm 1 The above option toggles Persistence Mode. It’s a GPU Attribute, which ensure Nvidia Driver remains loaded, even when an application is not runnin…

My personal GIT Cheat Sheet

Refresh a local working branch copy from origin $ git fetch --all
$ git reset --hard origin/master
Ignore given File in a Merge, e.g. defaults.php $ git merge --no-commit $ git reset HEAD myfile.txt $ git checkout -- myfile.txt $ git commit -m "merged "
Show history $ git log -p -2 -p, which shows the difference introduced in each commit. You can also use -2, which limits the output to only the last two entries
Go back to a previous version indicated by commitHash $ git reset --hard
Create a branch based off . Push the branch to remote repo $ git checkout -b $ git push --set-upstream origin
Ignore a file in Commit $ git add -u
$ git reset -- $ git commit -am “Log message”
Remove Untracked files and directories $ git clean -fd -n “d” is used here for directories. “n” is used to list, and not Remove as yet $ git clean -fd Remove the files & directories

HTTP works, HTTPS does not, on AWS

Image
Spent half a day figuring the issue on why all HTTP requests works, but HTTPS does not. Writing this Post on my journey from Oh Man!! to Wow Man!!
I am on AWS with following configuration EC2 instance with application code ELB load balancer SSL certificate from Amazon, attached to ELB
Used Postman for the request. None of the HTTP / HTTPS works. Postman returns a canned message with following troubleshooting options. Refer image Check server for response SSL connection blocked Cookies issue Request timeout


As request works fine in Browser, 1 is not applicable. Checked Server configuration and ruled out 2. 3 is not applicable. Increased timeout, but still couldn’t get it work.
Tried another Chrome REST client extension (DHC REST Client) to add variety to the test. HTTP works, HTTPS still does not work. Some progress.
Suspecting SSL Certificate, deleted it, created a new one. Attached it to the Load Balancer, but still HTTPS does not work.
Suspecting Load Balancer, deleted it, created a new one…

Animated GIF on Static Photo

Today, I will talk about a nifty trick to integrate animated GIFs in static Photos. Static images can be placed over Static photos in Snapchat, Instagram and Whatsapp. However, we will learn the technique to add animated sticker(s), aka GIF, over a photo.
The final photo will have both the visuals integrated. We will use following steps Extract frames from GIF* Place Frame 1 on static Photo Place Frame 2 on another copy of static Photo Repeat step 3, until all frame are placed Finally, take all static Photos from above steps, and create an animated GIF
To put multiple stickers on a photo, do following Extract frames from all GIFs Find GIF with maximum number of frames Loop through with termination counter set to number from Step 2 Add counters for other GIFs (e.g., GIF2 containing 3 frames, j=0) Place frame i (GIF1 frame), j (GIF2 frame), k (GIF3 frame) etc., on static Photo

AWS RDS incompatible-parameters solved

Recently, I rebooted one of my RDS (Mysql) instance, as it was hanging every now and then.

What should have been a breeze, became stormy. Instance rebooted, and picked wrong Parameter Group. The parameters, understandably, were not set with this instance in mind. The instance went in incompatible-parameters Status (i.e. DB Instance Status).

I figured the issue, and tried to change the right parameter group. BUT, because instance is in incompatible-parameters Status, the change will not be allowed. I tried looking with our friend Google on how to get my instance in Available status again, only to find that people already are in distress, from as long as 2010. There have been no plausible and easy solution to do this. Refer following

https://forums.aws.amazon.com/thread.jspa?threadID=237385https://forums.aws.amazon.com/thread.jspa?messageID=587725https://forums.aws.amazon.com/thread.jspa?threadID=55800 

BTW, I cannot change my Parameters Group values, as that Group is being used in a ot…

504 Gateway Timeout on Amazon AWS ELB (Elastic Load Balancer)

Faced it recently!!

The Client request is sending large data set to Server. Till date it worked fine on our Test & Staging servers. Put it on Live, and Kaput!!

Checked it across various clients, i.e. iOS, Android, Postman etc. Worked on all, but iOS. Increased time outs for Live to check, but still the same.

Eventually figured, Amazon ELB (Load Balancer) is timing out. ELB's idle timeout was 60 seconds. Increased it to 180 seconds, and Voila! it worked.

Load Balancers are nifty machines to help with keeping one address for outside world, and contain multiple sub addresses internally. ELB accepts the HTTP/HTTPs request which contains the large data set, and maintain a connection with the Client (along with a connection with Server). If client / instance does not send data in the duration specified in idle_timeout, the connection is closed by ELB.


HTTP Caching

Recently, I had to design static resource Caching to be able to optimize Network traffic and User experience on Client devices. The requirement was that Client should use Cache for a given picture, if it is unchanged at the Server. Request the fresh copy of picture, if changed.

As our requests are  HTTP REST API calls, we turned to it. HTTP gives multiple ways to control cache. I have explained them following, and why it didn't work for our case.

no-cache
instructs client to not cache the resource / response. This, of course, will not work, as Device should not request it from Server, if Available with Device and Unchanged in Server.

no-store
instructs client to not store the resource / response. This will not work for the same reason, as no-cache.

max-age instructs client to invalidate the resource / response, after number of seconds elapsed in max-age. This will not work too, as we cannot predict the changes to resource.
If-Modified-Since
sent by the Client / Device to query for Mo…

Download Own Video from Facebook

My son recently went on stage in our Church, and spoke about Father's day. It was a proud moment for me to see him talk in front of 300 people. I captured the short speech in my handycam.

I posted it to Facebook from my home PC. At work, a friend (not on facebook) wanted me to post the video on their whatsapp. As, its my own video, I went to Facebook to download it. To my surprise, it's not possible. I can Save it, but not Download it.

However, I found following technique to do that. I am sharing it here for someone's benefit

Type m.facebook.com in your Chrome browserGo to Video post (you can go through Notifications)Play the VideoWhile playing, Right click on the Video Click Save video as... to save it at your preferred location in computer
I know its easier to install an extension, but I did not wanted to do that just for this one time download. I have not tested it on other browsers.

ND Developers, My Nemesis and Others's Too

I bought a flat in ND Passion from ND Developers in 2013. At the time, I was comparing projects from DSR & Purva in the vicinity. As ND isn't a known name, I tried looking for reviews, and don't remember to find anything negative.

In the hindsight, it was a huge mistake. The very flat due to be delivered in next 3 months, took another 2 years to complete. For months together, there was no progress. I gave up on it, and then realizing there is no choice, took the fight up with few fellow flat owners. For months, going to ND office, meeting MD himself, getting another false hope, only to be disappointed again.

Knowing project will never complete, and in burden of both EMIs & rental, I decided to move in. I moved in with just one working lift(service, no pax lifts), and a swimming pool. No play area, skates area, pavers not laid out, block not painted etc. etc. Even when the'handover' took place, I ran pillar to post to get pending work done as small as latch in …

King David's response to Shimei Cursing

Bible tells us God called David A Man After My Own Heart

If we look at Samuel II Chapter 16 Verse 5 to 13, we see account of Shimei cursing David. David's response is exemplary in terms of his relationship with God.

David was fleeing Absalom, who had successfully dethroned David. David had to flee to save his life. Absalom was one of David's son and had kept a grudge against David and his half brother Amnon. Amnon had violated Tamar (Absalom's sister), but King did nothing because he loved Amnon.

David became king of Israel, after God had rejected king Saul and gave the throne to David. Shimei belonged to Saul's family, and held David responsible for Saul's dethrone and murder. However, David never killed Saul.

David was with his official and special guards (mighty men). Naturally, Abishai asked David's permission to cut Shimei's head and silence him. The David's response to this is accounted as...
..
..
10 But the king said, “What does this have to do wi…

iOS Push Notifications, Amazon SNS

Today, I set out to find answers for following 2 questions

Can APNS device token change?Does Amazon SNS handle token changes?
For 1st, I figured that device tokens can change. Apple developer docs mention following
Note: A device token is not a unique ID that you can use to identify a device. Device tokens can change after updating the operating system on a device. As a result, apps should send their device token
Looking at other sources, it seems OS update is not the only event that can change the device token. This includes Device Reset, Wrong Backup Restore (of a different device) and 2 years lifetime elapsed. Refer http://stackoverflow.com/a/7999690

Now, I wanted to know if this can be handled by Amazon SNS, instead of me creating a device token change notification from my app.  Turns out, Amazon SNS does handle it by disabling the end point, for which GCM / APNS has notified of expiry or replacement. SNS also notifies this through an event. GCM does a better job in its notification,…

Push Notifications to iOS not received from Amazon SNS

Took us 3 days to figure the problem. I jot down here for someone's benefit

Short answer: The problem was with Apple Certificate and Private Key. A new certificate generated, and Voila!!

For people who savor the Journey, more than the Result, Read on...

Our app (both iOS & Android) receives notifications for User actions. We have used Amazon SNS to deliver notifications.

Recently, one fine day, Notifications stopped. Naturally, knowing there is nothing wrong with Apple Notifications, we debugged our PHP code. Didn't find anything wrong. A day is spent.

Next day, we decided to eliminate application layer (PHP) from this testing, and test on Amazon SNS console. Amazon Console says, Delivered, but no Notification on the device. We tweak our application JSON payload, to no avail. We went ahead, tried example payload from http://docs.aws.amazon.com/sns/latest/dg/SNSMobilePushAPNSAPI.html in Step 7. That didn't work either. Tried delivering  RAW data, but no Notifiction on …

App Cabs woes in Bangalore

While we talk about, how App Cabs have made our life easier, there are 2 sides to this coin. For instance, today it took me more than 75 minutes of wait time (from first booking confirmation), 3 bookings,and almost 2 kms. of walking, to get into a cab. Today, after seeing a traffic jam outside my apartment, I decided to hail a cab, instead of driving. Booked first cab through TFS. As he was taking time, to help save it for both of us, started walking to meet him on the way. Decided to check on status before our rendezvous point. To my surprise, he has taken some other route, and is now further away from me. On being called, our language skills aren't a good match, and I am better off cancelling it. Tried Ola, as in my mind TFS sucks now. It showed cab 2 minutes away, which I happily booked, only to be confirmed that my cab is now 7 minutes away. Looking at cab's location, I know it can't reach me in less than 15 minutes. Cancelled it. Being stranded away from my house, and…

Remove MySQL SPs

Sub Procedures are MySQL way of giving decision implementation capability, that is beyond SQL queries.

Sub procedures are created and removed using CREATE PROCEDURE and DROP PROCEDURE. If you need to delete a SP (Sub Procedure), you can use following

DROP PROCEDURE IF EXISTS sp_name

However, at times, you may need to remove all the SPs, i.e. remove all sub procedures from the DB, or MySQL installation.

This may be required, if, for instance, you imported multiple SPs without using a database (i.e. use ). Instead of dropping them tediously one by one, you can remove them by using following


Remove all SPs from MySQL installation
mysql> DELETE FROM mysql.proc ;

Remove all SPs from a given Database
mysql> DELETE FROM mysql.proc WHERE database= '' AND type = 'PROCEDURE' ;