npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

maoda-db

v0.0.7

Published

一个扁平化的 kv 的 db,能读写到硬盘里,同时能充分利用内存减少 io 的开销

Downloads

2

Readme

introduction

一个扁平化的 kv 的 db,能读写到硬盘里,同时能充分利用内存减少 io 的开销

api

const DiskDb = require("maoda-db");

const db = new DiskDb("./db_dir");

// 异步,确认加载到 memory 了,如果没有,返回 false
db.loadBlock("5a930d801bd54095b0460fbe394e80c5");

// 同步读取,读之前,先 await loadBlock
db.getBlock("5a930d801bd54095b0460fbe394e80c5"); // 返回 block 数据 Promise<{code:0, data}>

// 同步设置
db.setBlock("5a930d801bd54095b0460fbe394e80c5", { age: 100 });

db.on((changedIds) => {
  console.log("监听到以下 block 被改动了", changeIds);
});

db.config(conf); // 配置,通常使用默认就好,见下面配置明细

notice

读了后马上写,必须是同步的,中间不能有其他 await 否则就 bug 了

config

const config = {
  minBlockIdLength: 32, // 最小 id 长度
  maxBlockSize: 100000, // 一个 block 的大小
  checkFreq: 60 * 1000, // 每分钟检查一次保存
  inactiveToSave: 60 * 1000, // 1 分钟不活跃,就存库
};

存储逻辑

持久化到硬盘里

  • 直接存储在硬盘的上,扁平化的放在一个目录里,文件名如:029882ab6ce3445f847b24e9784d197e-maoda

内存缓冲

  • 为了避免内存过大,定期从缓冲中移除并存入内存中,我们为每个 block 带上读写时间戳,按照时间戳早的,优先存入硬盘;
  • 上述的删除缓存入内存的事情,我们每分钟做一次
  • 我们也提供一个能力,全量写入硬盘,主要应对用户需要重启的情形