Table of Contents
Reply content:
Home Backend Development PHP Tutorial Design issues for distributed service governance?

Design issues for distributed service governance?

Oct 17, 2016 am 09:13 AM
dubbo fpm java php python

I used C++ to implement the [Registration Center] of the microservice, and implemented high availability for this registration center. My service network communicates through TCP. When the service goes online, it will be registered on the [Registration Center], and the [Registration Center] will push This server address goes to [Service Consumer]. In this way, the [Service Consumer] holds all the [Microservice Maps]. My load balancing is done in the [Service Consumer]. To put it bluntly, the [Service Consumer] needs to be resident in memory, so it is very important for Python. Or Java is easier to do, but for PHP using FPM, it is equivalent to a death sentence. How to transform PHP so that traditional FPM PHP can support this architecture. It seems that Dubbo is done in a similar way, so if the front-end is done in PHP, wouldn’t it be a bit of a pain in the ass?

Reply content:

There are two methods of load balancing:

Client load balancing, typically Finagle and Dubbo. The advantage is that it is simple to implement, and the service is directly connected and has good performance. The disadvantage is that when using multiple languages, you need to implement a client for each language.

Server-side load balancing, typical load balancers are Nginx and HAProxy. Usually a reverse proxy is added in front of the service. The client communicates with the server through a reverse proxy, and the specific load balancing logic is implemented by the load balancer. The load balancer itself can also be registered with the registry. The advantage is that the client is very simple and supports multiple languages. The disadvantage is that there is a bit of performance loss.

The specific choice depends on the business and the company’s technology selection. In a multi-language scenario, the server-side solution will save a lot of maintenance costs. Of course, if there is a team to maintain the client, I will not mention it. After all, what does the team need to do?

For pure Java scenarios, you have already used Dubbo or a similar framework. If the framework already provides support, don’t bother.

Back to the main scenario, if you have to implement service discovery in the PHP service, you can cache the service registry, such as putting it in memcache, and pull it again every once in a while.

Above The simplest (and probably the most reliable) solution is agent. Run an agent on the PHP server to monitor your registration center. This agent will modify the PHP configuration file after receiving the new address. When PHP is called by FPM Go read this configuration.

Generally speaking, almost all frameworks have configuration files. You can just modify this file directly. The modification does not increase any cost (because you also have to read the configuration file). This design method now has certain advantages, that is, some capabilities that belong to the service bus have been completely down-layered to the service consumer node. In this way, the bus itself has lighter functions and only manages service registration and distribution of registration information. The downtime of the registration center basically has no impact on service consumption and invocation.

In view of the problem you just mentioned, there are two solutions. One is to still improve the capabilities of the service agent back to the bus, including routing and load balancing. If you don't want to do this, you can also consider setting up a separate server to implement service consumption and routing balancing logic on this server. This server can be regarded as the back-end proxy corresponding to the PHP application. I think the use of client load balancing in microservices is a major trend. There are three reasons: first, it has performance advantages; second, it has higher reliability. Even if the registration center is down, it can still run normally; third, the client itself needs to implement circuit breakers and services. For logic such as downgrading, it would be a good idea to implement a simple load balancing logic. I am not very familiar with PHP. Is it possible to consider writing the service configuration into a certain service_config.php file and include this service_config.php in other files? Contains the timestamp of the previously detected file. If it exceeds a certain time (such as 1 minute), the configuration write file will be obtained from the registration center again. Two solutions

1. Swoole
Swoole: PHP’s asynchronous, parallel, high-performance network communication engine
You can use swoole to write a permanent internal test php server

2. Cache
use APCu (PHP: APCu - Manual) or redis, cache the server address list
It depends on the specific performance requirements and the consistency requirements of the service list. The consistency requirements are relatively high, and the cache can be shorter. If you are worried about the network overhead of redis cache reading and writing, you can use APCu This local cache swoole
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1658
14
PHP Tutorial
1257
29
C# Tutorial
1231
24
PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

Choosing Between PHP and Python: A Guide Choosing Between PHP and Python: A Guide Apr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Python: A Deep Dive into Their History PHP and Python: A Deep Dive into Their History Apr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP's Impact: Web Development and Beyond PHP's Impact: Web Development and Beyond Apr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

The Continued Use of PHP: Reasons for Its Endurance The Continued Use of PHP: Reasons for Its Endurance Apr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

Golang vs. Python: Performance and Scalability Golang vs. Python: Performance and Scalability Apr 19, 2025 am 12:18 AM

Golang is better than Python in terms of performance and scalability. 1) Golang's compilation-type characteristics and efficient concurrency model make it perform well in high concurrency scenarios. 2) Python, as an interpreted language, executes slowly, but can optimize performance through tools such as Cython.

Python vs. C  : Learning Curves and Ease of Use Python vs. C : Learning Curves and Ease of Use Apr 19, 2025 am 12:20 AM

Python is easier to learn and use, while C is more powerful but complex. 1. Python syntax is concise and suitable for beginners. Dynamic typing and automatic memory management make it easy to use, but may cause runtime errors. 2.C provides low-level control and advanced features, suitable for high-performance applications, but has a high learning threshold and requires manual memory and type safety management.

Python vs. C  : Exploring Performance and Efficiency Python vs. C : Exploring Performance and Efficiency Apr 18, 2025 am 12:20 AM

Python is better than C in development efficiency, but C is higher in execution performance. 1. Python's concise syntax and rich libraries improve development efficiency. 2.C's compilation-type characteristics and hardware control improve execution performance. When making a choice, you need to weigh the development speed and execution efficiency based on project needs.

See all articles