滑翔前人口数f
一种可供您使用而不是允许initdb运行(这是默认的)的预先被流行的FS. 这可以导致更快的起跑时间,因为initdb不需要运行.
安装方式 :
npm install @electric-sql/pglite-prepopulatedfs
此软件包包含一个存档, 作为静态资产, 您可以通过 dataDir() 函数.
* 信息 预先配置的FS是在我们的CI的基础上创建的,因此保证只为它创建的PGlite的相应版本工作. 如果您遇到问题, 请确保这个软件包与您的 PGlite 版本保持一致 . * :
安装
npm install @electric-sql/pglite-prepopulatedfs
# or
yarn add @electric-sql/pglite-prepopulatedfs
# or
pnpm add @electric-sql/pglite-prepopulatedfs
使用量
import { PGlite } from '@electric-sql/pglite'
import { dataDir } from '@electric-sql/pglite-prepopulatedfs'
// Create a PGlite instance with the prepopulated FS
const pg = await PGlite.create({
loadDataDir: await dataDir(),
})
例如,当您有多个测试时,每个测试都有它自己的 PGlite 实例时,这样做是有用的 。 考虑下列使用:
import { describe, it, expect, beforeEach } from 'vitest'
import { PGlite } from '@electric-sql/pglite'
import { dataDir } from '@electric-sql/pglite-prepopulatedfs'
describe('query and exec with different data sizes', () => {
let pg: PGlite
beforeEach(async () => {
pg = await PGlite.create({
loadDataDir: await dataDir(),
})
await pg.exec(`
// setup default data
`)
})
describe('test no. 1', () => {
...
})
describe('test no. 2', () => {
...
})
// many more tests here
})
虽然需要更多的带宽才能下载 @electric-sql/pglite-prepopulatedfs 软件包,由于 PGlite 不需要运行,测试会更快运行 initdb 每个人的.
同样的情况也适用于您的申请需要一次又一次地用一个干净的板块对PGlite进行即时处理。 您将初始化使用更多的带宽, 但会节省速度的长期.
基准制定
作为我们自动测试的一部分,我们做了一个简单的基准 packages/pglite-prepopulatedfs/tests/prepopulatedfs.test.ts。 。 。 .
以下是苹果M1上的样本输出:
initdb duration: prepopulated avg (trimmed) 263.38 ms vs. classic initdb 886.29 ms.
Speedup: 3.37x