Wednesday, May 16, 2018

Unravelling the mystery of AWS Cost reduction

What is AWS?


AWS, as most of us know, is a way of running a server without the hassle of maintenance costs, better up time and having the flexibility of owning the latest infrastructure, not to mention the possibility of ramping up or down on our resources flexibly.

Most of us have been using AWS as a matter of fact, without knowing much about the details.

If you have been using AWS for a long time, you would have noticed that the cost of running the server has been increasing over a period of time.

This is especially true, if you have been making changes to your server, creating new snapshots, stopping old instances, creating new instances and so on.


Did you wonder why AWS costs are increasing gradually?


The reason is that resources, once created/initiated, will cost us by the hour, however minuscule it may be.

So, the stopped instance, though it may not incur charges, as Amazon claims, the related resources, such as the volumes attached, the snapshots, the AMIs that you use, all add up to the cost that we would be paying for using the Amazon server at the end of the month.

Now, let us see what we can do to reduce our monthly AWS bill.


How do we Reduce AWS Billing costs?

In the first place, we need to identify the resources that are costing us, what are the resources that are costing us, how much each of these resources are costing us, we need to find the split up of the costs.

So, how do we do it? Once you login, go to the "Billing" page when you click under your name (top right)

This Billing dashboard gives you details about services/resources used and the cost till date.

You can select the month for which you want the bill to be shown.

For the present month, we can take a screenshot of the page today. Then come back tomorrow and take another screen shot. A three day screenshot would give us an idea about the cost incurred on every resource type per day; by calculating the difference from the first day to the second day to the third day.

If you notice, there is a category called "EC2-Other" . This is the area we need to focus on. This denotes the Volumes or disk usage for the running and the stopped instances. If we have many stopped instances, it also means that there are many volumes attached to them.

Essentially, these unused volumes or AWS resources are costing you by the hour.

Find out if these volumes are required now. If not, detach them; then delete them. It could cost you around $0.10 per GB per month. So, if you have unused volumes to the tune of 600GB, you could be paying an extra $60 per month on a regular basis.

Take snapshots of instances that you do not need now and then terminate them. If required, you can revive them from the snapshot information. Snapshots generally do not save the unused space. So, if you have a snapshot of a 50GB instance, it will save only the data that is contained in the 50GB instance. If your 50GB instance has 45GB of free space, you will be paying for only 5GB of snapshot storage.

Since, snapshots are stored in S3 by default, though you may not be able to see them in your S3 page, they cost much less than retaining them in the EBS.


Migrate your AWS server from old to new (m1 to t2)

One other option you should consider is to move your server from being in m1 to t2 or the latest.

The general idea is that these new servers provide better performance while costing up to 50% lesser.

The steps to follow would be to create launch a t2 server. Setup all the software necessary to create a copy of the existing m1 or m3 server.

Take a backup of all the source code, database, configuration files and scheduled job scripts/application.

Copy to the new t2 server.

Test the application in the t2 server. Time the migration properly in order to minimize or avoid downtime in the old server. Ideally, it should be at a time when traffic on the server is lean.

Test and then shutdown the old m1 or m3 server.

This exercise may help reduce the running cost of the instance by up to 50%.

Tuesday, January 09, 2018

The curious case of the htaccess file and the 500 Internal server error

.htaccess file and 500 Internal server error


Did you know that just a harmless change in the .htaccess file can result in your page not being opened at all?

Yes. It is possible.

I will explain it in a short while. [If you do not want to read this through, please go to the last paragraph, where the solution that we found is given]

The .htaccess file, for the uninitiated, is a linux file, resident on your web server. What it does is to act on a page or the files in a folder, based upon certain rules.

Mostly developers use it for renaming a common file to something meaningful for the search engines, so that they may find it, index it and show it in search results when people look for the topic discussed on that web page.

For example, one may have a common file called products.php, which is used to show various products that the vendor sells.

Invariably, products of a certain category are grouped together. And the group code may be sent as a parameter to the file, to change the view for the visitor.

So, products.php?i=19 may show inkjet printers, products.php?i=20 may show washing machines and so on.

The name products.php?i=19 does not make much sense. It makes better sense if it were to read like "inkjet printers with less expensive toner", because we all know how the printer companies rip customers off by offering cheap printers and expensive ink cartridges.

What we use the .htaccess file is to rewrite the url to something more meaningful for the viewer as well as to the search engine, like Google search.

The whole process runs like this. The prospective visitor posts a search for "500 internal server error" in the search.

In our case, it was problems.php?i=19 and it was indexed in the search engine as "htaccess-and-500-internal-server-error", because our .htaccess file renames and rewrites all requests for the specific page problems.php?i=19 to "htaccess-and-500-internal-server-error".

Now, coming to the point. We did something like this with our page. Only a single line was changed in the .htaccess file. And from the next moment onward, the entire site starts throwing this "Error 500 Internal server error".

When we removed the line, the pages started showing properly. So, we knew that the problem 500 Internal server error is related to the one line in the .htaccess file.

A close look at the code reveals that a space has been inadvertently placed in the url rewrite line.

Instead of "htaccess-and-500-internal-server-error", it was "htaccess-and-500-internal-server- error".

Solution to htaccess induced 500 Internal server error


A space had creeped in between server and error, thus invalidating the line.

The space was removed and the problem was solved.

Saturday, December 09, 2017

Locking Unlocking Aadhar Biometrics, Lock Unlock

Recently, there was a news item, which claimed that we can lock and unlock our Aadhar biometric details from being requested for biometric identification.

This seemed like a good feature. The news item also claimed that we can view if and when our biometric details were requested for identification.

This seems like a safety feature which the public may use to prevent misuse of their Aadhar information.

So, we went to the site address
https://resident.uidai.gov.in/biometric-lock

and filled in our Aadhar number.

So, were we able to lock our Aadhar?

Unfortunately, NO. Apparently, there was some "technical issue".

The page responded with the message "Your request cannot be processed now due to some technical issue. Please try again later."



Hopefully, the hiccup is temporary. And, will be rectified soon.

But, the fact remains that we are risking a situation of our biometric not being recognized in an important situation.

Assume that we had been able to lock our biometrics and are shown this message "Your request cannot be processed now due to some technical issue. Please try again later." when we are trying to unlock it.

So, there.

Wednesday, November 22, 2017

Nature, most benign, most benevolent!

We have this habit of blaming nature for all our ills.

Obviously, because man is the most intelligent creature on Earth and cannot go wrong.

Just imagine, what doesn't nature give us? Nature gives us light, energy, peace of mind, food, water and everything that is needed for our survival.

And, what do we do in return?

Do not let any chance to damage her physically and spiritually.

 

The better our knowledge of nature becomes, the worse becomes our treatment of her, making her angry.

What does nature do when she becomes angry?

She reacts in ways we cannot fathom.

Just let this sink in. The world has seen 2053 nuclear explosions since 1945. 


What Nature teaches us?



So, what are the lessons that we have to learn from nature.

We should all know that the benign, benevolent character of nature cannot be taken for granted. Because, our actions can change the quality of nature.

Nature or the cosmos cannot be overpowered, but it can be won over by our responsible actions which take nature into account, in all our actions.

It is not for nothing that our ancestors worshiped nature, which the modern religions rejected outright. It only shows our depredation and fall from grace.


Friday, November 17, 2017

Compressing jpg files; Which online tool is better?


Compress jpg files; Which is better?

 
We needed to place a few banner images on one of our web sites. The high resolution images were of the size of over 2MB. This is not ideal for a home page of a website. So, we decided to try a few image compression tools online.




The Image Compressing Challenge Contenders


We tried three image compression tools, such as compressjpeg.com, tinyjpg.com and compressjpg.online.

The first mentioned compressjpeg gave me a reduction of 72% from the original. To the untrained eye, there is no difference in the quality of the images.

The process was also pretty fast.

On the other hand, tinyjpg failed to upload my 2.5MB file twice and gave me a compressed file the third time.

Guess what, the online image compression tool shaved off 78% from the original image size.

Compressjpg, the third online tool that we tried, took a longer time to process the source image. The first attempt seemed to be a fail.

When trying the second time. File upload happens and there is a message which says the file was converted. But, the download link seemed like a Google adsense link.


So, of the two successful ones, the choice would be compressjpeg.com for speed and tinyjpg.com for better compression.

But, wait. There are other online tools like giftofspeed.com and jpeg-optimizer.com. Of these, jpeg-optimizer.com seems to be good choice, compressing the original image of size 2.4MB to a size of about 375K. That is cool 85% reduction in size.


giftofspeed.com, meanwhile gave a compression of about 71%.



The Image Compressing Champion


Finally, from our analysis of jpeg image compression tools, we found out that the following tools gave us image compression without apparent loss of quality. In order of compression efficiency, they would be http://www.jpeg-optimizer.com/, https://tinyjpg.com/, http://compressjpeg.com/ and https://www.giftofspeed.com/



The winner of the compression challenge would be jpeg-optimizer



Wednesday, November 08, 2017

jQuery not updating/switching a different tab div bootstrap tabs active class, Why?

We find that our bootstrap tabs active class not changing or working or switching and we wonder why. I had this problem of bootstrap tabs not switching and I will explain how I solved it, with an example. We are using jQuery to try switching bootstrap tabs programmatically automatically, using jQuery's set active tab on click.

We are trying to figure out and code how to change active tab in bootstrap using jQuery.

We find that our jQuery code is behaving not as we expect it to, which is, to say the least, very frustrating. Like, for example, we expect it to show a certain content in a certain bootstrap tab or div, but it updated the content in a different tab or div, instead. My jQuery was updating a different div.

The first time we encountered such a situation, it was frustrating. When you click on the tab or do it in the jQuery code and find that the bootstrap tabs are not switching, it really upsets you. You are setting the active tab using jQuery, but the bootstrap tab is not switching.

I have to state here that the key to finding a solution to a problem like this, or for any problem for that matter, is persistence. Also, try to split the problem into different small pieces.

It also helps to take a break; take our attention elsewhere and allow our sub-conscious to work on a solution.

Approaching the bootstrap class or div problem


In our case, there is also no specific error that is shown or seen in the debugger or developer tools window as we try and set active tab pane using javascript or jQuery. So, it becomes difficult to home in on the error. As with solving any problem, to solve bootstrap tabs active class not working, what we need is a cool mind and a some experience to troubleshoot in such a situation.

Taking time off from the task, addressing a different task and coming back at a later time helps, almost in all situations.

Here, I deduced that the most probable reason would be that the div that is getting updated is not closed. Some of the closing tags that should show the tab pane are missing.

So, the div or bootstrap class that you are updating is actually part of the previous named div and so the previous div / class is getting updated and not the one that you intended.

Solution: Close the previous div properly to create the differentiation. Check and compare the opening tags with the closing tags.

$( "#home" ).removeClass("active");
$( "#one" ).removeClass("active");
$( "#menu1" ).html( text );
$( "#menu1" ).addClass("fade in active");
$( "#two" ).addClass("active");
 

In the above jQuery script, div menu1 is updated with some html content.

Then the div with id menu1 is made active. Then #two is made active. #two here is a tab visualization. Two different tabs are created in this example to provide the visitor a feel of viewing two different screens.

In normal situations, this should provide the impression that a different tab is being viewed, due to the jQuery code.

But, in our case, it did not happen.

Because, our code looked something like this

<div id="home">
      <div id="menu1">
      </div>
</div>

In this case above, "menu1" becomes a subset of "home" and thus any update of the menu1 is reflected in "home".

The right code would have been

<div class="container">
     <div id="home">
     </div>
</div>

<div class="container">
     <div id="menu1">
     </div>
</div>

Proper closing of the tags, is very important.


A simple solution for when jQuery is not updating the right tab or div or class, but is updating a different tab, div or class.

It is frustrating till we understand and identify it; then it becomes easier to make the update of the right div, tab or class using jQuery.

jQuery updating a different tab different div bootstrap class SOLVED!

Tuesday, October 10, 2017

How to not print columns on display while printing on paper

Many of you may or may not be aware of a javascript code that is capable of printing page content.

We had created a report which looked something similar to the one shown below.
  

Notice that there are two columns that display "No" in orange colour. We want to print the report, but we do not want the "NO" columns to be printed on paper.


Hiding columns from a table using jQuery



jQuery has a simple command which can hide any number of cells based on their class names. That command to hide a class is given below.

$('.className').hide();


This command was given in the jQuery code, to be called when the print command was called.

Let us assume that we gave the classname "noprint" to all those cells in those two columns, which we do not want to print.

In the code loop, we added an additional classname called "noprint" to the content, like so.



 If you see, the  class "noprint" has been added. Now, when I give the command 

All cells that need to be hidden, have to be given the classname "noprint".

$('.noprint').hide();

All those cells that have noprint class in them are hidden from view.

We are using "class" and not "id" because of obvious reasons, the reasons being the "id" can appear only once in an entire page.


Printing using the system dialogue from web application


Now, the Print command may be used to call the system's print dialogue and get our page printed. See below for the code.




Solved.










Unravelling the mystery of AWS Cost reduction

What is AWS? AWS, as most of us know, is a way of running a server without the hassle of maintenance costs, better up time and having th...

Copyrighted.com Registered & Protected DWYE-NHTO-NBNH-7FFM