Pular para o conteúdo principal

Postagens

NestJS Clustering: Advanced techniques to increase NestJS Apps response

In today’s fast-evolving digital landscape, performance and scalability have become the lifeblood of modern applications. As advanced JavaScript developers, we continuously seek strategies to optimize our code and leverage every ounce of our infrastructure. NestJS clustering promises not just incremental improvements but exponential enhancements by fully unlocking the potential of your virtual machines. This article delves into NodeJS clustering within the NestJS framework, exploring its theoretical underpinnings, offering practical, code-rich examples, and even highlighting an experimental twist that can set your application apart. Unlocking the Power of NodeJS Clustering At its core, NodeJS clustering is about taking full advantage of multi-core systems. Typical NodeJS apps run as single-threaded processes, which can be a bottleneck when you need to handle a massive number of concurrent operations. Clustering allows you to spin up multiple worker processes that share the same server ...
Postagens recentes

NodeJS Concurrency: Mastering the Event Loop for High-Throughput Apps

In today’s rapidly evolving development landscape, mastering concurrency in NodeJS is not just an advantage, it's a necessity. For intermediate developers seeking to elevate their skills, understanding the nuances of NodeJS's non-blocking I/O model and the underlying event loop can be a game changer. This article dives into practical strategies, code samples, benchmarks, and even an experimental twist to help you optimize your applications for high throughput. Understanding the Event Loop and Asynchronous Flows At the heart of NodeJS's performance lies the event loop, a mechanism that handles asynchronous operations, ensuring your applications remain responsive even under heavy loads. Unlike traditional threading, NodeJS relies on non-blocking I/O to process tasks, effectively scheduling callbacks and promise resolutions for when data is ready. Breaking Down the Fundamentals Non-Blocking I/O : Instead of waiting for an I/O operation like file reads or database queries, Node...

Article: Optimizing PHP: Performance Tuning and Beyond

In today’s fast-paced digital landscape, every millisecond counts. For intermediate to advanced PHP developers, optimizing performance is not just an optional enhancement, it’s a necessity. Whether you’re running large-scale applications or fine-tuning high-traffic websites, understanding and implementing sophisticated performance strategies can set your projects apart. In this post, we’ll explore some base concepts that are necessary to improve PHP applications such as benchmarking, caching, debugging memory leaks, and even dive into experimental methods that push the boundaries of what PHP can do. I will try to present them with the code as simplest as possible to enable everybody to understand how simple is the actual concept but I urge you to search for a more updated and viable ways (according to your situation) to do that what is presented here. 1. Benchmarking and Profiling: Knowing Your Performance Baseline There is an old saying that goes "you can't control what you d...

Article: Preventing Database Gridlock: Recognizing and Resolving Deadlock Scenarios

Learn how deadlocks occur in database systems, understand their impact on performance, and discover practical techniques for identifying potential deadlock scenarios in your SQL code.

General: Prevent arbitrary precision arithmetic

Demand Some simple decimal calculations like 4.6 * 100 may lead in irregularities when dealing with numbers. Description During arithmetic operations like addition, subtraction, multiplication, and division, the numbers are manipulated according to the rules defined by the IEEE 754 standard. However, due to the finite precision of the representation, rounding errors may occur, leading to small discrepancies between the expected and actual results of computations. In simpler terms, the computer operates using powers of 2 (binary-based), so whenever we need to work with a number that cannot be exactly represented in binary (like 0.1, which is a base-10 fraction), it uses an approximation rather than an infinite number and is incapable of presenting the exact correct value. To prevent it we may use some libraries to prevent the problem. In Javascript and Typescript we have the BigNumbers library (and others). PHP has a built-in library for arbitrary-precision arithmetic called BCMath (Bin...

SQL: Unique Key constraint name convention

  Demand ALWAYS name unique key as "uq_{IndexName}" Description We use this convention to easily identify the source of the failure, especially in schema updates. When creating a CONSTRAINT we create its name starting with the string "uq", followed by the full name of the source table column used to build the index. Both separated by "_" (underline). Examples 1: CREATE TABLE customers ( 2:     id INT NOT NULL, 3:   name VARCHAR(100) NOT NULL, 4:    user_id INT NULL COMMENT 'if the customer have a system login it will be refernced here', 5:      PRIMARY KEY (id), 6: UNIQUE KEY `uq_user_id` (`user_id`), 6:      CONSTRAINT `fk_customers_user_id_users_user_id` 7:           FOREIGN KEY (`user_id`) 8:      REFERENCES `users` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION 9: ); Examples Explanation Here the  uq_user_id  is used to build a unique key...

SQL: Primary Key constraint name convention

Demand ALWAYS name forein keys constraints as "fk_{LocalTableName}_{LocalColumnName}_{DestinationTableName}_{DestinationFieldName}" Description We use this convention to easily identify the source of the failure, especially in schema updates. When creating a CONSTRAINT we create its name starting with the string "fk", followed by the full name of the source table, also called local table or child table, followed by the name of the column used in the source table to store the value to be searched for later in the target table, the name of the target table and finally the name of the field in the target table. All separated by "_" (underline). Examples 1: CREATE TABLE customers ( 2:     id INT NOT NULL, 3:   name VARCHAR(100) NOT NULL, 4:    user_id INT NULL COMMENT 'if the customer have a system login it will be refernced here', 5:      PRIMARY KEY (id), 6:      CONSTRAINT `fk_customers_user_id_users_user_id` 7:...