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

perf: 优化hyperf启动耗时, 元数据分类缓存, 有效缩短扫描时间 #644

Merged
merged 6 commits into from Oct 3, 2019
Merged

perf: 优化hyperf启动耗时, 元数据分类缓存, 有效缩短扫描时间 #644

merged 6 commits into from Oct 3, 2019

Conversation

daodao97
Copy link
Member

@daodao97 daodao97 commented Sep 30, 2019

由于常规开发中 vendor 下的代码一般不会被修改, 所以 vendor 下元数据缓存的利用率就会很高, 此处改动能有效降低 php bin/hyperf.php start 启动耗时
本机硬件配置:

  • MacBook Pro (13-inch, 2017, Two Thunderbolt 3 ports)
  • CPU 2.3 GHz Intel Core i5
  • 内存 8 GB 2133 MHz LPDDR3
    原本扫描时间: app 大概在 1s 左右, vendor 大概在 5s 左右
    优化后缩短在1s左右

@limingxinleo
Copy link
Member

limingxinleo commented Oct 2, 2019

现在增加了缓存机制,理论上扫描时,如果不清除缓存是不会扫描的。。

unset($exploded[count($exploded) - 1]);
$dirPath = implode('/', $exploded);
if (! is_dir($dirPath)) {
mkdir($dirPath, 0755, true);
}
}

$data = implode(PHP_EOL, [$pathsHash, $cacher->serialize()]);
file_put_contents($this->cachePath, $data);
$data = implode(PHP_EOL, [$pathsHash, base64_encode(serialize($meta))]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里缓存太大了。。整个 ast注解树都进来了,我下午改一下。。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

典型的使用场景: 修改代码->停止服务->重启服务,
而此时就算开启缓存, 由于文件最后修改时间变更, 同样会触发全盘的缓存更新, 所以对于这种典型场景, 缓存就失去了意义
此时 app 和 vendor 分别缓存的优势就体现出来了, 因为对于 hyperf 的使用者来说, 仅会修改 app 下的代码 @limingxinleo

Copy link
Member

@huangzhhui huangzhhui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @daodao97 !!!

@huangzhhui huangzhhui merged commit 60ab0b2 into hyperf:master Oct 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants