Thursday, June 29, 2023

Calculating Server Capacity: A Comprehensive Tutorial

 In this tutorial we will explore the process of calculating server capacity. Let's get started.

  • Understanding Server Capacity
  • Identifying Workload Characteristics
  • Estimating Resource Requirements
  • Calculating Required Server Capacity
  • Scaling for Future Growth

Understanding Server Capacity:
Server capacity refers to the ability of a server or a cluster of servers to handle the expected workload. It involves assessing various factors such as CPU, memory, storage, network bandwidth, and concurrent connections to determine the hardware and configuration needed to meet performance goals.
Identifying Workload Characteristics:
Begin by analyzing the workload characteristics to understand the demands on the server. Consider the following factors:
a. Average and peak number of users/requests per unit of time
b. Types of requests (e.g., static content, dynamic content, database queries)
c. Data transfer rates
d. Processing time for each request
e. Required response time or latency
Estimating Resource Requirements:
To estimate the resource requirements, consider the following:
a. CPU: Calculate the average and peak CPU usage based on the processing time per request and the number of requests per unit of time.
b. Memory: Estimate the memory requirements by considering the memory footprint of your application and the number of concurrent users/requests.
c. Storage: Determine the storage needs based on the amount of data to be stored and accessed by the server.
d. Network Bandwidth: Calculate the required bandwidth by considering the data transfer rates and the number of concurrent connections.
e. Redundancy and Failover: Account for redundancy and failover mechanisms, such as backup servers or load balancing, if necessary.
Calculating Required Server Capacity:
Now that you have estimated the resource requirements, follow these steps to calculate the required server capacity:
a. Calculate the total CPU capacity required by summing up the average and peak CPU usage for all requests.
b. Determine the total memory capacity required by adding the estimated memory requirements for each concurrent user/request.
c. Compute the required storage capacity by considering the amount of data to be stored and accessed.
d. Calculate the required network bandwidth based on the data transfer rates and concurrent connections.
e. Consider the redundancy and failover mechanisms to determine the number of backup servers or load balancing requirements.
Scaling for Future Growth:
It's important to consider future growth and scalability. Ensure that your server capacity can accommodate projected increases in workload over time. Consider factors such as business growth, user base expansion, and expected increases in traffic. You may need to revisit your calculations periodically to adjust the server capacity accordingly.
Conclusion:
Calculating server capacity is a crucial step in designing a robust and scalable infrastructure. By carefully analyzing workload characteristics and estimating resource requirements, you can determine the optimal server capacity to meet performance goals and accommodate future growth. Regular monitoring and adjustment will ensure that your infrastructure remains efficient and capable of handling increased demand.

Sunday, August 5, 2018

How to add bootstrap to your angular project?


How to install bootstrap?



  • Use one of the commands below depending upon the package manager you are using.
npm install bootstrap
gem install bootstrap -v 4.1.3

check file size before adding bootstrap, when you run ng serve command, in command prompt you will see the file size.

  • Add an entry in app.component.css
@import "~bootstrap/dist/css/bootstrap.css";

  • Create a button in the app.component.html with following class property.

class='btn btn-primary'

prior adding bootstrap it will be around 15kb, however, after adding bootstrap it will increase

Below is the extract from terminal which shows increased size.
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 227 kB [initial] [rendered]


Friday, July 27, 2018

Java & Spring Interview Questions

  1. Can Interface have static methods?
  2. What's difference between Interface with default method and Abstract class?
  3. If java is not allowing creating default method in Interface then what is use of abstract classes?
  4. Can a class have method with same name as that of constructor?
  5. Try{} finally{} will it work without a catch statement?
  6. try{ return 1; } finally{ return 2; }
    What will be the output? 
    1. Compilation error 
    2. 1 will be returned
    3. 2 will be retruned
    4. Unreachable return statement
  7. What is difference between String equals and == 
  8. Design problem - You have a remote DB having millions of records on which we have no control and you need to query it for data like you send id and wait for a value which hours to return. How will you get around this situation. You can replicate whole remote DB as it has trillions of data. 
  9. Design problem: You show the stock and prices. There are bunch of stocks who's price may change every millisecond. You are pulling this info from other DB, where you have no control.
  10. Design problem  -  Design a snake and ladders game. Tell what data structure you will use.
  11. Can you override a static method?
  12. How Hashmap works?
  13. What java collections you have worked with?
  14. What is difference between ArrayList and LinkedList
  15. What is difference between @RestController and @Controlle
  16. Which modules you worked on?
  17. What benefits spring jdbc provides over jdbc?
  18. what happens if the request is sent on the server.
  19. How can you control what loads when in an ExtJS page.
  20. HTML life cycle
  21. Javascript Singleton vs. observer
  22. Ext JS version 5 vs. 4.
  23. What is MVC and how it is useful?
  24. What is lazy loading?
  25. How do create and object and extend it?
  26. Can you extend a singleton object in javascript?
  27. What is difference between having and where clause.
  28. Can you have where, group by and having together
  29. What does spring boot provide? convention over configuration, get you up and running quickly, stand-alone production grade apps
  30. How to avoid serialising a subclass?
  31. How many objects will be created in sb.append(“Ram”).append(“shyam”).append(“mohan”);
  32. What is supper interface of collection?
  33. What characteristics Employee need to have to be candidate for hashmap keys?
  34. Immutable, equals, hashmap
  35. Whats new in Java 7?
  36. What is executer & executers?
  37. What is difference between Cylindrical and….latches
  38. What is adapter design pattern - How will you achieve ListIterator functionality with Iterator?
  39. Hibernate:
  40. Diff. between get and load?
  41. What is detached, how to reattach?
  42. Spring:
  43. how to provide dependancy of type prototype to singleton?

The last person in a race puzzle

Question: You are in a race, you overtook the last person, what's your position? 

Answer:


I think 3 answers need to be told here...


1. You are last so you can't overtake yourself.


2. You are second last if you overtake last person except you.


3. You are first because, you overtook everyone else and this was the last remaining person.


4. If there are laps, then possibilities increase further more.


It's possible that interviewee might be judging if you are the out of the box thinker and if you can come up with multiple solutions to a problem an chose the ultimate one.

Leave your replies...

Wednesday, April 11, 2018

Table is not created automatically in h2 embedded db or I'm unable to see the tables


Solution: In the browser, h2console,  change the database url to jdbc:h2:mem:testdb


Monday, February 19, 2018

How to download ExtJS free version?

ExtJS is a product by Sencha. They provide 2 licenses. 1. Commercial and 2. GPL. For your own learning you can download the free version with GPL license from below link.

ExtJS Download

Friday, February 16, 2018

How to keep a thread running in java?

To elaborate more on this question, there are situations in your application where you have a java service which keeps on polling for something like a table and based on some condition it will invoke some business api or methods. However, to keep this thread running what techniques can be used.

 Post your replies in comments section and I will add the answer here whichever sounds more appropriate.

Spring Interview Questions and Answers

What is difference between @RestController and @Controller?

  • @Controller is used to mark classes as Spring MVC Controller.
  • @RestController is a convenience annotation that does nothing more than adding the @Controller and @ResponseBody annotations
    So the following two controller definitions should do the same
    @Controller
    @ResponseBody
    public class MyController { }
    
    @RestController
    public class MyRestController { }

Which Spring Modules have you worked on?

Some mostly used spring modules are,
  1. Spring MVC
  2. Spring AOP
  3. Spring Security
  4. Spring JDBC
  5. Spring Core
  6. Spring Web-MVC
  7. Spring Boot
You may refer spring.io for more details of each module.

What benefits spring JDBC provides over jdbc?

The JDBC abstraction framework provided by Spring consists of four different packages:
  • The core package contains the JdbcTemplate. This class is one of the fundamental classes provided by and used by the Spring framework's JDBC support.
  • The datasource package is a great fit for unit testing database access code. Its DriverManagerDataSource can be used in a way that is similar to what you are already used to from JDBC: just create a new DriverManagerDataSource and call the setter methods to set DriverClassNameUrlUsername, and Password.
  • The object package contains classes that represent RDBMS queries, updates, and stored procedures as thread safe, reusable objects.
  • The support package is where you can find the SQLException translation functionality and utility classes.
The Template Design Pattern

Spring JDBC implements the Template design pattern, meaning the repetitive plumbing parts of the code are implemented in template classes. This approach simplifies the use of JDBC, since it handles the creation and release of resources. This helps to avoid common errors like forgetting to close the connection. It executes the core JDBC workflow tasks like statement creation and execution, leaving application code to provide SQL and extract results.

Spring JDBC Exception Handling

The Spring framework addresses the problems faced in traditional JDBC programming with the following solutions:
  • Spring provides an abstract exception layer, moving verbose and error-prone exception handling out of application code into the framework. The framework takes care of all exception handling; application code can concentrate on extracting results by using appropriate SQL.
  • Spring provides a significant exception hierarchy for your application code to work with in place of SQLException.
With the help of an abstract exception layer, we achieve database independence without having to change the exception handling. For example, if you change your database from PostgreSQL to Oracle, you do not have to change the exception handling from OracleDataException to PostgresDataException. Spring catches the application-server-specific Exception and throws a Spring data exception.
When dealing with exceptions, Spring examines the metadata available from a database connection to determine the database product. It uses this knowledge to map SQLException to the correct exception in its own hierarchy. So, we need not worry about proprietary SQL state or error codes; Spring's data access exceptions are not JDBC-specific, so your DAOs are not necessarily tied to JDBC because of the exceptions they may throw.

What is Spring MVC and how it is useful?

Model - holds data eg. Bean
View - Contains view code like JSP, HTML page.
Controller - Controller holds business logic. Binds View and Models together.

Mainly MVC allows different components to be modified with no or very less side effects.


What features does spring boot provide? 



  • convention over configuration, get you up and running quickly, stand-alone production grade apps
  • Create stand-alone Spring applications
  • Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files)
  • Provide opinionated 'starter' POMs to simplify your Maven configuration
  • Automatically configure Spring whenever possible
  • Provide production-ready features such as metrics, health checks and externalized configuration
  • Absolutely no code generation and no requirement for XML configuration

What is an aspect?

Aspect: a modularization of a concern that cuts across multiple classes. Transaction management is a good example of a crosscutting concern in J2EE applications. Any class can be an aspect.

Declaring an aspect

With the @AspectJ support enabled, any bean defined in your application context with a class that is an @AspectJ aspect (has the @Aspect annotation) will be automatically detected by Spring and used to configure Spring AOP. The following example shows the minimal definition required for a not-very-useful aspect:
A regular bean definition in the application context, pointing to a bean class that has the @Aspect annotation:
<bean id="myAspect" class="org.xyz.NotVeryUsefulAspect">
   <!-- configure properties of aspect here as normal -->
</bean>
And the NotVeryUsefulAspect class definition, annotated with org.aspectj.lang.annotation.Aspect annotation;
package org.xyz;
import org.aspectj.lang.annotation.Aspect;

@Aspect
public class NotVeryUsefulAspect {

}

Tuesday, January 30, 2018

I am a new joiner? How should I deal with challenges? How can I make that first impression?

I'm a new joiner. How do I get started faster, and make that first impression.


Being in IT world, being a developer, QA or project manager, it's not uncommon to land in a situation, where you have just joined a project and you have no idea where to start. How to start contributing most effectively. How to make that first impression. So here I'm outlining few ways you can deal with the situation.


Knowledge Transfer(a.k.a. KT)

          Knowledge transfer means people who have spent some time in the project help a new joiner to get started with the understanding of the project. However, there are very less organisations, projects where this happens properly. Several times there is friction between vendors and employees in the company. So they hesitate to share, fearing they would loose their job, if they transfer their knowledge to someone else. They want to create and keep the dependency on them so that they can keep their job for a longer term. However, this is one of the harmful things for an organisation. As just like money, knowledge should flow through the system, so it will be of most use.

       So in short, to give your best shot, you may not expect any knowledge sharing and assume that you are on your own in this treasure hunt game. So what is the next thing you should look forward to?


Project documents

      In organisations these days it's a legal binding to keep things documented. So there is a great chance that things are documented. Only thing is you need to find out what documents you should look for. For a software project, mainly documents are the artefacts generated at various stages of software development. Just to list a few, Architecture diagrams, Requirement Specifications, Functional Requirement Documents, Business Requirement Documents, Technical design documents, Unit test documents, flow charts, Test Cases, Release notes, Implementation plans, Support manuals, User manuals, help documents, ER Diagrams, Schema diagrams etc.

   You need to sceman through all these documents whichever available and connect the dots.


Database Schema


     To increase your understanding of the project at a faster pace, best thing you can do is try understanding the database schema and see how different entities in the system are related to each other. Where you can look for information. How data is organised. Try to understand the way tables are named. How they are related to UI if any.

User Interface

If your system has User Interface, then it is a good idea to run through some or the most possible modules of the system. Relate these modules to database schema. Try to understand how authentication happens. How many tiers system is having. Are their any UI patterns used. Patterns help understand the system faster.

Run through code

Scanning through code and relating it to UI and DB schema is also one of the most helpful ways to understand a system. 

Keep your notes

You can use text files, doc files or excel sheet to keep your mostly needed information handy. The information can be frequently needed team contacts, team delivery list/groups, server names, todo items, frequently needed queries etc.

Setup a debug environment

Most systems can be setup on developer's machine. If you have this at your disposal, please set it up. This is the most effective way to understand the system's internal workings. Get help of a colleague who has already done it. Debug the system by setting up debug points at various places and try to understand the data flow.

Understanding processes

There could be different ways projects are run, budgeted. Various ways new deliverables are handled. So get yourself familiarised with your organisations' ways. What systems are used for tracking? How deadlines are tracked? What project cycles are followed? etc.

I will keep on adding to this post. However, if you have any other ideas, please do post them in the comment. Also, mention if there are any books on this topic. One I can think most related is Clean Coder. That explains most effectively what is expected out of a coder.

Calculating Server Capacity: A Comprehensive Tutorial

 In this tutorial we will explore the process of calculating server capacity. Let's get started. Understanding Server Capacity Identifyi...