Skip to main content

Posts

Showing posts from 2019

Terraform in 10 mins

Terraform is  "infrastructure-as-code" and there is a list of many tools over the internet to do your job: Puppet SaltStack Chef Ansible CloudFormation Terraform can manage existing and popular service providers as well as custom in-house solutions. Configuration files describe to Terraform the components needed to run a single application or your entire datacenter. Setup: Download terraform from ->  Terraform Follow steps given in the link to setup your machine ->  Install First Terraform Script: Create new file example.tf,  here .tf is extension of terraform files If you don't have an AWS account, create one now. I will be using resources which qualify under the AWS free-tier, meaning it will be free.  If you already have an AWS account, you may be charged some amount of money, but it shouldn't be more than a few rupees at most. once you have created new AWS account then go ahead and install AWS-CLI from...

Big O calculation rules

There are rules which helps us to identify Big O notations. Rule 1 :- Worst case Rule 2 :- Remove Constants Rule 3 :- Different terms for input Rule 4 :- Drop Non dominants Rule 1: The very first role when it comes to big-O that is worst case when calculating big. if you look at above function we're looping through the entire array to find "rakesh". 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 package com . algo . practise ; import java.util.concurrent.TimeUnit ; public class Performance { public static void main ( String [] args ) { String ar [] = { "rks" , "rk" , "rakesh" , "singhania" , "kumar" }; long timeMilli1 = System . nanoTime (); for ( int i = 0 ; i < ar . length ; i ++) { System . out . println ( "Loop" ); if ( ar [ i ]. equals ( "rakesh" )) { System . out . p...

Big O notation

Big-O Analysis of Algorithms The Big O notation defines an upper bound of an algorithm, it bounds a function only from above. Don't get too hung up on this.  We want to use this as an example to measure how long it takes for this function to run.  We can do this in Java by saying let's say Time0 is going to  start this timer before the loop happens. And then when the loop ends I'm going to have another timer called T-1   package com. algo . practise ; import java.util.Arrays ; import java.util.concurrent.TimeUnit ; public class Performance { public static void main (String[] args) { String ar[] = { "rks" , "rk" , "rakesh" , "singhania" , "kumar" }; // Returns current time in millis long timeMilli1 = System. nanoTime (); for ( int i = 0 ; i < ar. length ; i++) { if (ar[i]. equals ( "rakesh" )) { System. out . println ( "found" ); } } long timeMil...

Logging in AWS lambda

Problem : Logs are very important aspect of any microservice or any AWS service and in AWS if your rate of generating Cloudwatch logs is high ,then  it can increase your AWS costs significantly. There should be some limit on the growth of the logs to keep costs under control. Solution : There are multiple ways to manage the logging. Let's begin with some of the best practices and then some framework level changes which can help in reducing the overall logging. Best Practices : 1. Most of the times we are only interested to find error scenarios from the logs so it is important to use log.error while logging error cases. Never use other logging levels for logging errors 2. Never use print statements instead use a proper logging framework to log the statements 2. Be diligent about the log statements and categorize them correctly at different log levels : DEBUG , INFO , ERROR 4. Don't log data unless there is a critical need for same. Eve...