3

Preface

First of all, thank all Hyperf supporters. In the two years since its release, we have insisted on releasing a small version every week. Up to now, we have released more than 106 versions. This is the most direct way for the Hyperf team to convey the spirit of persistence and responsibility to users. In a way, we use actions to explain everything, and we will continue to maintain Hyperf iteration and maintenance in the future.

At the same time, we are also honored to see more and more companies choose Hyperf as the framework of their company projects, and give back a lot of Pull Requests and Bugfixs to Hyperf. At present, there are more than 200 Contributors of Hyperf. Thank you for co-creating it. With ecological prosperity, we will certainly live up to expectations!

Thanks ALL

Thanks All Contributors

In the process of continuous iteration, we have produced some new ideas. We iterated and verified these ideas, and finally settled in version 2.2. It is an honor to announce to you today that Hyperf 2.2 version is released!

Main function iteration

Reconstruction of the bottom layer of DI

In version 2.0-2.1, in order to realize that AOP acts on non-DI managed objects (such as objects new keywords), the underlying implementation uses BetterReflection components to implement related functions, bringing a new programming experience, but also There are still some problems that have not been overcome before, as follows:

In the new version, we abandon the BetterReflection , and use the sub-process scanning method to solve the previous problems. The , we have solved all ~

uses a positive angle to describe this feature change :

  • Without caching, the startup time is reduced by an order of magnitude. Take a giant project of the author's company as an example. The original startup time is as long as 5 minutes, and the new version only takes 10 seconds!
  • Enriched the Inject annotation injection, but unfortunately there is still one case that is invalid (the parent class private fails when the attributes are injected, which is consistent with the performance of the previous version), we will continue to work hard to overcome the realization of this scenario
  • Support PHP 8 and Attributes native annotation features

In short, as one of the core components of Hyperf, DI components have now reached a brand new stage, with full innovation and practical value~

Support PHP 8

Hyperf 2.2 each component has been adapted PHP 8 , notes also compatible PHP 8 of Attributes native annotation features.

<?php
namespace App\Controller;

#[Controller]
class IndexController
{
    #[GetMapping("/test")]
    public function index()
    {
        ...
    }
}

It should be noted that same area and use annotations (Annotations) and native annotations (Attributes), the bottom layer will annotations (Annotations) (even if the annotations are different)

<?php
namespace App\Controller;

/**
 * @Controller
 * 同一区域同时使用,注解(Annotations) 无效
 */
#[Middleware(TestMiddleware::class)]
class IndexController
{
    // 单独使用,可以支持
    #[Inject]
    protected StdoutLoggerInterface $logger;
    
    /**
     * 单独使用,可以支持
     * @GetMapping("/test")
     */
    public function index()
    {
        ...
    }
}

It should be noted that although the framework already supports PHP8 , you still need to confirm whether the business code and dependent third-party components meet the PHP 8 incompatible change .

Repeatable annotation

In the previous version, the same area of the same Annotation cannot be reused:

/**
 * @AutoController()
 * @Middleware(FooMiddleware::class)
 * @Middleware(BarMiddleware::class)
 * 重复 @Middleware 只有一个生效!
 */
class IndexController
{
    
}

Previously, reusing the same annotations could only be achieved through annotation nesting:

/**
 * @AutoController()
 * @Middlewares({
 *     @Middleware(FooMiddleware::class)
 *     @Middleware(BarMiddleware::class)
 * })
 * 非常繁琐,增加额外心智负担
 */
class IndexController
{
    
}

In 2.2, we implemented repeatable annotation :

<?php
namespace App\Controller;

#[AutoController]
#[Middleware(FooMiddleware::class)]
#[Middleware(BarMiddleware::class)]
class IndexController
{
    
}

When the user-defined annotation needs to be repeatable, just change the parent class of the annotation to Hyperf\Di\Annotation\AbstractMultipleAnnotation . For details, please refer to the implementation of the annotations in the Middleware

The configuration center is completely refactored

In the previous version, the implementation of the configuration center was implemented by various scattered components. The implementation of each component was different, and there were some differences in the implementation of details. The code overlap between the components was also very high. In version 2.2 we perfect reconstruction related components, increased hyperf/config-center assembly configured as a center and a uniform abstraction layer access layer, to implement correlation storage capacity of the driving engine in conjunction with other configurations driver assembly center, as hyperf/config-center + hyperf/config-apollo components are used in combination to realize the use of the Apollo configuration center. Other drivers only need to replace the corresponding drivers. This transformation allows us to greatly reduce the amount of driver code. Now a few lines of code and several classes can complete a new driver access.

When upgrading and using, pay attention to the changes of the relevant configuration files. The new version will be config/autoload/config_center.php configuration file to control all relevant information. The file can be php bin/hyperf.php vendor:publish hyperf/config-center command for the initial creation.

Service governance component reconstruction

In the previous version, the hyperf/service-governance component is the same as the problem faced by the configuration center. We have also made similar changes to the configuration center in this version, for example, through the hyperf/service-governance + hyperf/service-governance-nacos component to realize the use of nacos as a service center.

When upgrading and using, pay attention to the changes of the relevant configuration files. The new version will be config/autoload/services.php configuration file to control all relevant information. The internal structure has certain changes. The file can be php bin/hyperf.php vendor:publish hyperf/service-governance command for the first time creation.

Complete refactoring of Nacos components

Important: Be sure to re-read the component documentation! ! !

We do Nacos component of the complete reconstruction , the code for the implementation of the components, the hierarchical structure and API more reasonable, and the original distribution center integration logic within a module, and client service centers logic code Split, as shown in the introduction of the two main iterative functions above.

For specific use of Nacos components, you must read the new document again and use it according to the new document instructions.

Reconstruction of AMQP component connection mechanism

We found that there are many users who use AMQP components, and as a message queue component, its performance speed has a very large impact on the system's peak clipping effect and message delivery/consumption speed. We implemented it through the coroutine channel (Channel) A multiplexing mechanism has nearly doubled the message delivery performance of this component! While the performance is improved, the stability of the connection between the client and the server has been improved.

After the component is upgraded, it will directly switch to the new connection mechanism without any adjustment.

The following is the key information in the extraction of pressure test comparison:

Non-Confirm mode delivery

2.1 version

The maximum number in the connection pool is set to 10
$ ab -c 32 -n 10000 http://127.0.0.1:9501/
Requests per second:    5340.80 [#/sec] (mean)
Time per request:       5.992 [ms] (mean)
Time per request:       0.187 [ms] (mean, across all concurrent requests)
Transfer rate:          928.38 [Kbytes/sec] received

2.2 version

Set up 2 multiplexed connections
$ ab -c 32 -n 10000 -k http://127.0.0.1:9501/
Requests per second:    9101.44 [#/sec] (mean)
Time per request:       3.516 [ms] (mean)
Time per request:       0.110 [ms] (mean, across all concurrent requests)
Transfer rate:          1626.53 [Kbytes/sec] received
Confirm mode delivery

2.1 version

The maximum number in the connection pool is set to 10
$ ab -c 32 -n 5000 -k http://127.0.0.1:9501/ 
Requests per second:    797.73 [#/sec] (mean)
Time per request:       40.114 [ms] (mean)
Time per request:       1.254 [ms] (mean, across all concurrent requests)
Transfer rate:          142.56 [Kbytes/sec] received

2.2 version

Set up 2 multiplexed connections
$ ab -c 32 -n 5000 -k http://127.0.0.1:9501/Requests per second:    1595.94 [#/sec] (mean)Time per request:       20.051 [ms] (mean)Time per request:       0.627 [ms] (mean, across all concurrent requests)Transfer rate:          285.21 [Kbytes/sec] received

3 Incubator components graduated into the main library

Since using the Incubator mechanism to incubate components, a large number of new components have been produced. I am honored that in version 2.2, 3 Incubator components have graduated and entered the main library, which also means that these components have entered the production usable stage~

The following are the components of each graduation and their introduction

hyperf/dag

This component is a lightweight directed acyclic graph ( D irected A cyclic G raph) task orchestration library, through which the task can be arranged and run easily.

hyperf/rpc-multiplex

This component is an RPC protocol connection component that realizes multiplexing. By using this library, RPC functions with higher performance and more stable connections can be obtained;

hyperf/rpn

This component is an implementation component of reverse Polish notation. RPN is a mathematical expression method introduced by Polish mathematician Jan Vukasevic in 1920. In reverse Polish notation, all operators are placed in the operands. Later, it is also called suffix notation. Inverse Polish notation does not require parentheses to identify the precedence of operators. Through this component, the analysis of reverse Polish expressions can be completed.

Dependency upgrade

  • Upgrade friendsofphp/php-cs-fixer to ^3.0 ;
  • Upgrade psr/container to ^1.0|^2.0 ;
  • Upgrade egulias/email-validator to ^3.0 ;
  • Upgrade markrogoyski/math-php to ^2.0 ;
  • Upgrade league/flysystem to ^1.0|^2.0 ;
Dependencies have changed
  • #3577 domnikl/statsd abandoned and no longer maintained. The author suggests to use the slickdeals/statsd package instead;

API will be deprecated

  • #3636 Hyperf\Utils\Resource will v2.3 , please use Hyperf\Utils\ResourceGenerator instead;

Change details

  • #3334 LengthAwarePaginator::toArray() the return value of Paginator::toArray() to be consistent with 060f54627adbed;
  • # 3550 from kafka removed broker and bootstrap_server , use brokers and bootstrap_servers in place;
  • #3580 Change the default priority of the aspect to 0;
  • #3582 change AMQP to an empty string;
  • #3634 Use Fork Process strategy to replace BetterReflection strategy;

    • # 3649 in hyperf/database use gen:model removed when roave/better-reflection ;
    • # 3651 in LazyLoader removed in roave/better-reflection ;
    • # 3654 removed in other components roave/better-reflection ;
  • #3676 use promphp/prometheus_client_php instead of endclothing/prometheus_client_php ;
  • #3694 change Hyperf\CircuitBreaker\CircuitBreakerInterface to support PHP8 ;

    • Change CircuitBreaker::inc*Counter() to CircuitBreaker::incr*Counter() ;
    • Change the type hint AbstractHandler::switch()
  • # 3706 in PHP8 will @Middlewares({@Middleware(FooMiddleware::class)}) change the writing style #[Middlewares(FooMiddleware::class)] ;
  • #3715 refactor nacos component, must to reread the document;
  • #3722 deleted config_apollo.php configuration, please use config_center.php ;
  • #3725 deleted config_etcd.php configuration, please use config_center.php ;
  • #3730 deleted brokers and update_brokers configuration from kafka
  • #3733 deleted zookeeper.php configuration, please use config_center.php ;
  • #3734 #3772 divided nacos into config-nacos and service-governance-nacos ;
  • #3734 Rename the nacos-sdk component name to nacos ;
  • #3737 Refactor configuration center and configuration driver

    • Add AbstractDriver and merge the repeated code into the abstract class
    • Add PipeMessageInterface to obtain the message structure of the process in a unified configuration
  • #3817 #3818 separate the service-governance-consul component from the service-governance component;
More

Upgrade guide

We provide a detailed upgrade guide, please refer to the official document- 2.2 Upgrade Guide

Official website and communication

Github 👈👈👈👈👈 Click Star to support us
Gitee Code Cloud 👈👈👈👈👈 Click Star to support us
Hyperf official website
Hyperf document
Hyperf Exchange Group: 862099724 (full)
Hyperf Exchange 2 Group: 811414891 (full)
Hyperf exchange 3 groups: 589051831
A group of nails: 34538367 (full)
Ding Ding Group Two: 34488757


huangzhhui
2.3k 声望564 粉丝

Creator of Hyperf