Skip to main content

Generate the table size from a Database.

SELECT
  TABLE_NAME AS `Table`,
  ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024) AS `Size (MB)`
FROM
  information_schema.TABLES
WHERE
  TABLE_SCHEMA = "blog"
ORDER BY
  (DATA_LENGTH + INDEX_LENGTH)
DESC;

If you don’t care about all tables in the database and only want the size of a particular table, you can simply add AND TABLE_NAME = "your_table_name" to the WHERE clause. Here we only want information about the book table:

SELECT
  TABLE_NAME AS `Table`,
  ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024) AS `Size (MB)`
FROM
  information_schema.TABLES
WHERE TABLE_SCHEMA = "blog"
  AND
    TABLE_NAME = "posts"
ORDER BY
  (DATA_LENGTH + INDEX_LENGTH)
DESC;

MySql Slow query Log.

If you want to increase your application performance you need to find out where your system is going to slow. For MySQL-based applications, you can easily find out which query is slow just by enabling the slow query log.

mysql -u root -p

SET GLOBAL slow_query_log = 'ON';

By default, when the slow query log is enabled, it logs any query that takes longer than 10 seconds to run. But you can change this interval time by type the following command, replacing X with the time in seconds:

mysql -u root -p

> SET GLOBAL long_query_time = X;

Initially location is: /var/lib/mysql/hostname-slow.log.
But you can change the query log location:

mysql -u root -p

> SET GLOBAL slow_query_log_file = '/path/filename';

We can also indicate to log queries which not using indexes. which is very helpful.

mysql -u root -p

> SET GLOBAL log_queries_not_using_indexes = 1;

To find out the current slow query log location.

mysql -u root -p

> show global variables like 'slow%log%'; 

The parameter changes are lost after MySQL reboots because the parameters are set dynamically, so in order to make the changes permanent, we need to set up the parameters in the MySQL configuration file (/etc/mysql/my.cnf)

[mysqld]
slow-query-log = 1
slow-query-log-file = /var/log/mysql/mysql-slow.log
long_query_time = 5
log-queries-not-using-indexes = 1

We can also check the variable/parameters values as 


> SHOW GLOBAL VARIABLES LIKE 'slow_query_log';
> SHOW GLOBAL VARIABLES LIKE 'long_query_time';

What is AWS CloudFront?

  • Its a content Delivery Network(CDN).
  • It Improves read performance, content is cached at the edge.
  • 216 Point of Precesecne globally (edge locations).
  • It DDos protection, integrations with Shield, AWS Web Application Firewall.
  • Can Expose external HTTPS and can talk to internal HTTPS backends.

Cloud Front – Origins

  • S3 Bucket
    • For distributing files and caching them at the edge.
    • Enhanced security with CloudFront Origin Access identity (OAI)
    • CloudFront can be used as an ingress (to upload files to S3)
  • Custom Origin(HTTP)
    • It can be any HTTP end point like ALB(Applicatiion Load Balancer)
    • It can be EC2 instance(Ec2 instance must be public)
    • S3 static website.

S3 Storage Classes

AWS has many kind of S3 storage class

Amazon S3 Standard (S3 Standard)

1. Designed for high durability of 99.999999999% of objects across multiple Availability Zones.
2. If you store 10,000000 objects with Amazon S3, you can on average expect to incur a loss of a single object once every 10,000 years.
3. 99.99% Availability over a given year.
4. Sustain 2 concurrent facility failures.

Use case:
Big data analytics, mobile & gaming applications, content distribution…

Amazon S3 Standard-Infrequent Access (S3 Standard-IA)

  1. Suitable for data that is less frequently accessed but requires rapid access when needed.
  2. Designed for high durability of 99.999999999% of objects across multiple Availability Zones.
  3. Low cost compared to Amazon s3 Standard
  4. 99.99% Availability
  5. Sustain 2 concurrent facility failures.

Use case:
As a data store for disaster recovery, backups…..

Amazon S3 One Zone-Infrequent Access (S3 One Zone-IA)

  1. Same as AI but is stored in a single AZ.
  2. High durability of 99.999999999% of the object in a single AZ. That means data loss when your AZ is destroyed.
  3. 99.95% Availability.
  4. Low latency and high throughput performance
  5. Low cost compared to AI (by 20%)

Use case:
Storing secondary backup copies of on-remise data, or storing any kind of data so that we can recreate.

S3 Intelligent-Tiering

  1. Low latency and high throughput performance as S3 Standard.
  2. Small monthly monitoring and auto-tiering fee.
  3. Automatically moves objects between two access tiers based on changing access patterns.
  4. Designed for high durability of 99.999999999% of objects across multiple Availability Zones.
  5. 99.99% Availability over a given year.

Amazon S3 Glacier

  1. Low-cost object storage meant for archiving/ backup
  2. Data is retained for the longer term(10s of year).
  3. It’s a big alternative to on-premise magnetic tape storage.
  4. The average annual durability is 99.999999%.
  5. Cost per storage per month ($0.0041/GB) + retrieval cost.
  6. Each item in Glacier is called “Archive” (up to 40TB).
  7. Archives are stored in “Vaults”.

Use case:
Storing secondary backup copies of on-remise data, or storing any kind of data so that we can recreate.

S3 Replication

Before Create S3 bucket replication we should consider some things which are mention below.

  1. After enabling Replication only new objects are replicated not those which are previously created.
  2. Delete operations are not replicated.
  3. We cannot create chaining replication.

What is MongoDB URI?

Lets understand what is MongoDB URI?

MongoDB URI is a connection string which usually uses for connecting MongoDB server and client. for example

 mongodb+srv://brigitte:bardot@xyz-1234.srv.net/admin

 mongodb+srv 

this is call srv uri string. SRV string start with mongodb+srv prefix which tell mongodb server uri string.
 brigitte:bardot

here brigitte is mongodb server credential user name. bardot is password

 xyz-1234.srv.net 

xyz-1234.srv.net is host name
 admin

admin is authenticate database. that crential is match into this database.


Factory Method Pattern

Official definition :

Defines an interface for creating an object, but lets subclass decide which class to instantiate. Factory method lets a class defer instantiation to subclass.

So factory method pattern is a pattern that manipulate the product functionality but not instantiate the product object, a subclass take decision to make which class it instantiate by extend or implement the abstract creator class. Abstract creator class has no knowledge of the actual product that will be created.Object creation is totally depend on subclass.

For example


abstract class  PizzaStore
{
    public function orderPizza($type) {

        $piza = null;
        $piza = $this->createPizza($type);

        $piza->prepare();
        $piza->bake();
        $piza->cut();
        $piza->box();
        return $piza;

    }

    abstract function createPizza($type);
}

Here PizzaStore our main AbstractCreator class which extent by Concrete Subclass NyStylePizzaStore. And NyStylePizzaStore class take decision to make which class it will instantiate.


class NyStylePizzaStore extends PizzaStore
{

    function createPizza($type)
    {
        if ($type == "chesse") {
            return new NyStyleChessePizza();
        } else if ($type == "peporoni") {
            return new NyStylePeporoniPizza();
        } else if ($type == "clam") {
            return new NyStyleClamPizza();
        } else if ($type == "veggie") {
            return new NyStyleVeggiePizza();
        } else {
            return null;
        }
    }
}





class NyStyleClamPizza extends Pizza
{

    public function __construct()
    {
        $this->storeName = "NyStyle";
    }
}

/**
 * Pizza File
 *
 * @author Md.Atiqul haque <md_atiqulhaque@yahoo.com>
 */




abstract class Pizza implements Store
{
    protected $storeName;

    public function bake()
    {
        echo  "----" . "Baking....<br>";
    }

    public function prepare()
    {
        echo "----" . "Preparing piza for {$this->storeName}...<br>";
    }

    public function cut()
    {
        echo "----" . "Cutting...<br>";
    }

    public function box()
    {
        echo  "----" . "Boxing...<br>";
    }

    public function getName()
    {
        return $this->storeName;
    }
}


/**
 * Store File
 *
 * @author Md.Atiqul haque <md_atiqulhaque@yahoo.com>
 */




interface Store
{
    public function bake();

    public function prepare();

    public function cut();

    public function box();
}

$pizaStore = new NyStylePizzaStore();

$pizaStore->orderPizza('clam');

Out put will be
—-Preparing piza for NyStyle…
—-Baking….
—-Cutting…
—-Boxing…

SOLID design principle

SOLID is an acronym. which full meaning is

S – Single-responsibility principle
O – Open-closed principle
L – Liskov substitution principle
I – Interface segregation principle
D – Dependency Inversion Principle

When a developer develop a software if he flows this principle it is easy to maintenance and reuse and test his module. let see what is S.O.L.I.D is.

Understanding “S”- SRP (Single responsibility principle)

A class should have one and only one reason to change, meaning that a class should have only one job.

For example Student class represent student

Understanding “O” – Open closed principle

Objects or entities should be open for extension, but closed for modification.

Understanding “L”- LSP (Liskov substitution principle)

Every subclass/derived class should be substitutable for their base/parent class.

Understanding “I” – ISP (Interface Segregation principle)

A client should never be forced to implement an interface that it doesn’t use or clients shouldn’t be forced to depend on methods they do not use.

Understanding “D”- Dependency inversion principle

Entities must depend on abstractions not on concretions. It states that the high level module must not depend on the low level module, but they should depend on abstractions.