Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

熔断器熔断状态不能正确开启 #3967

Closed
yuzhua-fangzhen opened this issue Aug 20, 2021 · 8 comments · Fixed by #3979
Closed

熔断器熔断状态不能正确开启 #3967

yuzhua-fangzhen opened this issue Aug 20, 2021 · 8 comments · Fixed by #3979
Assignees
Labels
bug Something isn't working

Comments

@yuzhua-fangzhen
Copy link

#寻求大佬帮助
/**
* @CIRCUITBREAKER(failCounter=1, fallback="App\Controller\IndexController::index", timeout=0.01)
*/
public function add()
{
$a = $this->request->input('a',100);
$b = $this->request->input('b',100);
return $this->calculatorService->add($a,$b);
}

public function index()
{
    return '服务熔断了';
}

debug信息:
[DEBUG] App\Controller\IndexController::add success, use 1.0054850578308s.
[DEBUG] The current state is closed.
[DEBUG] App\Controller\IndexController::add success, use 1.0047399997711s.
[DEBUG] The current state is closed.
[DEBUG] App\Controller\IndexController::add success, use 1.0051550865173s.
[DEBUG] The current state is closed.
[DEBUG] The duration=12.561861991882s of closed state longer than the annotation duration=10s and is reset to the closed state.
[DEBUG] App\Controller\IndexController::add success, use 1.0037009716034s.
[DEBUG] The current state is closed.
[DEBUG] App\Controller\IndexController::add success, use 1.0025861263275s.
[DEBUG] The current state is closed.
[DEBUG] App\Controller\IndexController::add success, use 1.0041949748993s.
[DEBUG] The current state is closed.
[DEBUG] The duration=10.756902933121s of closed state longer than the annotation duration=10s and is reset to the closed state.
[DEBUG] App\Controller\IndexController::add success, use 1.0021090507507s.
[DEBUG] The current state is closed.

@yuzhua-fangzhen yuzhua-fangzhen added the question Further information is requested label Aug 20, 2021
@limingxinleo
Copy link
Member

只开一个进程测试

@yuzhua-fangzhen
Copy link
Author

https://github.com/limingxinleo/hyperf-demo/tree/breaker
大佬,您好,我用你的这个代码测试是可以触发熔断的,我把 /** * @CircuitBreaker(failCounter=1, fallback="App\Controller\IndexController::index", timeout=0.1) */ public function breaker() { $this->service->client()->get('/sleep'); // sleep(1); // throw new BusinessException(ErrorCode::SERVER_ERROR, 'breaking...'); return $this->response->success('breaking...'); }
换成‘/**

  • @CIRCUITBREAKER(failCounter=1, fallback="App\Controller\IndexController::index", timeout=0.01)
    */
    public function add()
    {
    $a = $this->request->input('a',100);
    $b = $this->request->input('b',100);
    return $this->calculatorService->add($a,$b);
    }’
    calculatorService是我在本地创建的一个服务提供者,就不能触发熔断了,你上面的说的只开一个进程测试我没太明白是什么意思,可以具体说一下是什么原因吗,为什么rpc调用的时候就不能触发熔断

只开一个过程测试

@yuzhua-fangzhen
Copy link
Author

@limingxinleo
现在是只开一个进程测试,还是不行
debug的信息
[fangzhen@localhost consumer]$ php bin/hyperf.php start
[DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\Config\Listener\RegisterPropertyHandlerListener listener.
[DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\RpcClient\Listener\AddConsumerDefinitionListener listener.
[DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\JsonRpc\Listener\RegisterProtocolListener listener.
[DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\ExceptionHandler\Listener\ExceptionHandlerListener listener.
[DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\DbConnection\Listener\RegisterConnectionResolverListener listener.
[DEBUG] Event Hyperf\Framework\Event\BeforeMainServerStart handled by Hyperf\Process\Listener\BootProcessListener listener.
[DEBUG] Event Hyperf\Framework\Event\MainWorkerStart handled by Hyperf\ServiceGovernance\Listener\RegisterServiceListener listener.
[INFO] Worker#0 started.
[INFO] HTTP Server listening at 0.0.0.0:9501
[DEBUG] Event Hyperf\Framework\Event\AfterWorkerStart handled by Hyperf\Server\Listener\AfterWorkerStartListener listener.
[DEBUG] Event Hyperf\Framework\Event\AfterWorkerStart handled by Hyperf\Server\Listener\InitProcessTitleListener listener.
[DEBUG] App\Controller\IndexController::breaker success, use 2.0026998519897s.
[DEBUG] The current state is closed.
[DEBUG] App\Controller\IndexController::breaker success, use 2.0014669895172s.
[DEBUG] The current state is closed.
[DEBUG] App\Controller\IndexController::breaker success, use 2.0024809837341s.
[DEBUG] The current state is closed.
[DEBUG] App\Controller\IndexController::breaker success, use 2.0028629302979s.
[DEBUG] The current state is closed.
[DEBUG] The duration=12.207475185394s of closed state longer than the annotation duration=10s and is reset to the closed state.
[DEBUG] App\Controller\IndexController::breaker success, use 2.0044801235199s.
[DEBUG] The current state is closed.
[DEBUG] The duration=10.386277914047s of closed state longer than the annotation duration=10s and is reset to the closed state.
[DEBUG] App\Controller\IndexController::breaker success, use 2.0035848617554s.
[DEBUG] The current state is closed.

@limingxinleo
Copy link
Member

server.php 配置贴一下

@limingxinleo limingxinleo added bug Something isn't working and removed question Further information is requested labels Aug 25, 2021
@limingxinleo limingxinleo self-assigned this Aug 25, 2021
@yuzhua-fangzhen
Copy link
Author

server.php 配置贴一下
@limingxinleo
这是服务提供者的配置
return [
'mode' => SWOOLE_PROCESS,
'servers' => [
[
'name' => 'http',
'type' => Server::SERVER_HTTP,
'host' => '0.0.0.0',
'port' => 9501,
'sock_type' => SWOOLE_SOCK_TCP,
'callbacks' => [
Event::ON_REQUEST => [Hyperf\HttpServer\Server::class, 'onRequest'],
],
],
[
'name' => 'jsonrpc-http',
'type' => Server::SERVER_HTTP,
'host' => '0.0.0.0',
'port' => 9502,
'sock_type' => SWOOLE_SOCK_TCP,
'callbacks' => [
Event::ON_REQUEST => [Hyperf\JsonRpc\HttpServer::class, 'onRequest'],
],
],
],
'settings' => [
Constant::OPTION_ENABLE_COROUTINE => true,
Constant::OPTION_WORKER_NUM => 1,
Constant::OPTION_PID_FILE => BASE_PATH . '/runtime/hyperf.pid',
Constant::OPTION_OPEN_TCP_NODELAY => true,
Constant::OPTION_MAX_COROUTINE => 100000,
Constant::OPTION_OPEN_HTTP2_PROTOCOL => true,
Constant::OPTION_MAX_REQUEST => 100000,
Constant::OPTION_SOCKET_BUFFER_SIZE => 2 * 1024 * 1024,
Constant::OPTION_BUFFER_OUTPUT_SIZE => 2 * 1024 * 1024,
],
'callbacks' => [
Event::ON_WORKER_START => [Hyperf\Framework\Bootstrap\WorkerStartCallback::class, 'onWorkerStart'],
Event::ON_PIPE_MESSAGE => [Hyperf\Framework\Bootstrap\PipeMessageCallback::class, 'onPipeMessage'],
Event::ON_WORKER_EXIT => [Hyperf\Framework\Bootstrap\WorkerExitCallback::class, 'onWorkerExit'],
],
];
这是服务提供者的实现类namespace App\JsonRpc;

use Fangzhen\Rpcservice\JsonRpc\CalculatorServiceInterface;
use Hyperf\RpcServer\Annotation\RpcService;

/**

  • @RpcService(name="CalculatorService",protocol="jsonrpc-http",server="jsonrpc-http",publishTo="consul")
    */
    class CalculatorService implements CalculatorServiceInterface
    {
    public function add(int $a,int $b):int
    {
    sleep(1);
    return $a + $b;
    }
    public function minus(int $a,int $b):int
    {
    return $a - $b;
    }
    }

这是服务消费者的调用
`class IndexController extends AbstractController
{
/**
* @Inject
* @var CalculatorServiceInterface
*/
protected $CalculatorService;

/**
 * @CircuitBreaker(timeout=0.05,failCounter=1,fallback="App\Controller\IndexController::indexFallback")
*/
public function index()
{
    $a = $this->request->input('a',100);
    $b = $this->request->input('b',50);

    $result = $this->CalculatorService->add($a,$b);
    return $result;
}
public function indexFallback()
{
    return '服务降级了';
}

}`

@yuzhua-fangzhen
Copy link
Author

@limingxinleo
使用了composer require "hyperf/circuit-breaker:2.2.x-dev" 这个包熔断是生效的,官方什么时候能修复这个bug?

@limingxinleo
Copy link
Member

下周一发版本

@yuzhua-fangzhen
Copy link
Author

@limingxinleo
composer require "hyperf/circuit-breaker:2.2.x-dev"
这个包在bug修复之前都可以用是吗?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants