Skip to content

Commit 9b9bb09

Browse files
authored
Merge pull request #783 from docs/imporoving
docs: update /guide/improving-performance
2 parents 8311e9e + 38b7d98 commit 9b9bb09

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

guide/improving-performance.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ export default defineConfig({
5858

5959
:::
6060

61-
## Limiting directory search
61+
## 限制搜索目录 {#limiting-directory-search}
6262

63-
You can limit the working directory when Vitest searches for files using [`test.dir`](/config/#test-dir) option. This should make the search faster if you have unrelated folders and files in the root directory.
63+
你可以通过 [`test.dir`](/config/#test-dir) 选项限制 Vitest 搜索文件的工作目录。如果根目录中存在不相关的文件夹和文件,这将加快搜索速度。
6464

65-
## Pool
65+
## 运行池 {#pool}
6666

6767
默认情况下,Vitest 在 `pool: 'forks'` 中运行测试。虽然 `'forks'` 池更适合解决兼容性问题([hanging process](/guide/common-errors.html#failed-to-terminate-worker)[segfaults](/guide/common-errors.html#segfaults-and-native-code-errors)),但在较大的项目中,它可能比 `pool: 'threads'` 稍慢。
6868

@@ -86,7 +86,7 @@ export default defineConfig({
8686

8787
:::
8888

89-
## Sharding
89+
## 分片 {#sharding}
9090

9191
测试分片是将你的测试套件拆分成多个组或分片的过程。当你拥有大量的测试用例,并且有多台机器可以同时运行这些测试的不同子集时,这个功能会非常有用。
9292

@@ -106,11 +106,11 @@ vitest run --reporter=blob --shard=3/3 # 3rd machine
106106
vitest run --merge-reports
107107
```
108108

109-
::: details GitHub Actions example
110-
This setup is also used at https://github.com/vitest-tests/test-sharding.
109+
::: GitHub Actions 详细示例
110+
同样方案也应用于 https://github.com/vitest-tests/test-sharding 仓库。
111111

112112
```yaml
113-
# Inspired from https://playwright.dev/docs/test-sharding
113+
# 灵感来至于 https://playwright.dev/docs/test-sharding
114114
name: Tests
115115
on:
116116
push:
@@ -178,17 +178,17 @@ jobs:
178178
:::
179179
180180
:::tip
181-
测试分片在多 CPU 数量的机器上也很有用
181+
测试分片在多核心 CPU 机器上也很有用
182182
183183
Vitest 将只在其主线程中运行一个 Vite 服务器。其余的线程用于运行测试文件。
184-
在高 CPU 计数的机器中,主线程可能会成为瓶颈,因为它无法处理来自线程的所有请求。例如,在 32 CPU 机器中,主线程负责处理来自 31 个测试线程的负载。
184+
在多核心 CPU 机器中,主线程可能会成为瓶颈,因为它无法处理来自其余线程的所有请求。例如,在 32核 CPU 机器中,主线程负责处理来自 31 个测试线程的负载。
185185
186-
为了减少主线程的 Vite 服务器的负载,可以使用测试分片。负载可以在多个 Vite 服务器上进行平衡
186+
为了减少主线程的 Vite 服务器的负载,可以使用测试分片。将负载平均到多个 Vite 服务器上
187187
188188
```sh
189-
# Example for splitting tests on 32 CPU to 4 shards.
190-
# As each process needs 1 main thread, there's 7 threads for test runners (1+7)*4 = 32
191-
# Use VITEST_MAX_THREADS or VITEST_MAX_FORKS depending on the pool:
189+
# 以32核心CPU拆分成4个分片为例。
190+
# 每个分片需要一个主线程,因此每个分片可以分配7个测试线程 (1+7) *4 =32
191+
# 使用 VITEST_MAX_THREADS 进行分配:
192192
VITEST_MAX_THREADS=7 vitest run --reporter=blob --shard=1/4 & \
193193
VITEST_MAX_THREADS=7 vitest run --reporter=blob --shard=2/4 & \
194194
VITEST_MAX_THREADS=7 vitest run --reporter=blob --shard=3/4 & \

0 commit comments

Comments
 (0)