admin管理员组文章数量:1356448
I am using pouchDB
with IndexedDB
adapter on chrome browser and I want to calculate the each IndexedDB database size. I use the code from .js to do the calculation.
What I found is that the total size of the databases is far greater than the webkit temporary storage usage.
Below screenshot is the total storage (255MB) used by my application.
You will see there are 5 databases saved in IndexedDB
. And below output is the calculation result for the size of each database. You will see that the total size is about 389MB. I wonder why they are quite different. Which one is the correct one?
--------- _pouch_products -------------
VM1633:51 - attach-seq-store : 0 B
VM1633:51 - attach-store : 0 B
VM1633:51 - by-sequence : 86.7 MB
VM1633:51 - detect-blob-support : 2 B
VM1633:51 - document-store : 92.3 MB
VM1633:51 - local-store : 6.1 KB
VM1633:51 - meta-store : 96 B
VM1633:57 TOTAL: 179.0 MB
--------- _pouch_transactions -------------
VM1633:51 - attach-seq-store : 0 B
VM1633:51 - attach-store : 0 B
VM1633:51 - by-sequence : 13.7 KB
VM1633:51 - detect-blob-support : 2 B
VM1633:51 - document-store : 2.2 KB
VM1633:51 - local-store : 4.2 KB
VM1633:51 - meta-store : 96 B
VM1633:57 TOTAL: 20.2 KB
--------- _pouch_products-mrview-4c294f20854f412a71c9e7cf2f9cc58f -------------
VM1633:51 - attach-seq-store : 0 B
VM1633:51 - attach-store : 0 B
VM1633:51 - by-sequence : 11.9 MB
VM1633:51 - detect-blob-support : 0 B
VM1633:51 - document-store : 35.3 MB
VM1633:51 - local-store : 15.1 MB
VM1633:51 - meta-store : 136 B
VM1633:57 TOTAL: 62.3 MB
--------- _pouch_products-mrview-fdca57d512425c6ed0f20311a4f8d6d1 -------------
VM1633:51 - attach-seq-store : 0 B
VM1633:51 - attach-store : 0 B
VM1633:51 - by-sequence : 86.2 MB
VM1633:51 - detect-blob-support : 0 B
VM1633:51 - document-store : 44.2 MB
VM1633:51 - local-store : 17.4 MB
VM1633:51 - meta-store : 136 B
VM1633:57 TOTAL: 147.7 MB
--------- _product_alerts -------------
VM1633:57 TOTAL: 0 B
I am using pouchDB
with IndexedDB
adapter on chrome browser and I want to calculate the each IndexedDB database size. I use the code from https://github./jonnysmith1981/getIndexedDbSize/blob/master/getIndexedDbSize.js to do the calculation.
What I found is that the total size of the databases is far greater than the webkit temporary storage usage.
Below screenshot is the total storage (255MB) used by my application.
You will see there are 5 databases saved in IndexedDB
. And below output is the calculation result for the size of each database. You will see that the total size is about 389MB. I wonder why they are quite different. Which one is the correct one?
--------- _pouch_products -------------
VM1633:51 - attach-seq-store : 0 B
VM1633:51 - attach-store : 0 B
VM1633:51 - by-sequence : 86.7 MB
VM1633:51 - detect-blob-support : 2 B
VM1633:51 - document-store : 92.3 MB
VM1633:51 - local-store : 6.1 KB
VM1633:51 - meta-store : 96 B
VM1633:57 TOTAL: 179.0 MB
--------- _pouch_transactions -------------
VM1633:51 - attach-seq-store : 0 B
VM1633:51 - attach-store : 0 B
VM1633:51 - by-sequence : 13.7 KB
VM1633:51 - detect-blob-support : 2 B
VM1633:51 - document-store : 2.2 KB
VM1633:51 - local-store : 4.2 KB
VM1633:51 - meta-store : 96 B
VM1633:57 TOTAL: 20.2 KB
--------- _pouch_products-mrview-4c294f20854f412a71c9e7cf2f9cc58f -------------
VM1633:51 - attach-seq-store : 0 B
VM1633:51 - attach-store : 0 B
VM1633:51 - by-sequence : 11.9 MB
VM1633:51 - detect-blob-support : 0 B
VM1633:51 - document-store : 35.3 MB
VM1633:51 - local-store : 15.1 MB
VM1633:51 - meta-store : 136 B
VM1633:57 TOTAL: 62.3 MB
--------- _pouch_products-mrview-fdca57d512425c6ed0f20311a4f8d6d1 -------------
VM1633:51 - attach-seq-store : 0 B
VM1633:51 - attach-store : 0 B
VM1633:51 - by-sequence : 86.2 MB
VM1633:51 - detect-blob-support : 0 B
VM1633:51 - document-store : 44.2 MB
VM1633:51 - local-store : 17.4 MB
VM1633:51 - meta-store : 136 B
VM1633:57 TOTAL: 147.7 MB
--------- _product_alerts -------------
VM1633:57 TOTAL: 0 B
Share
Improve this question
asked Apr 2, 2019 at 10:23
Joey Yi ZhaoJoey Yi Zhao
42.8k87 gold badges357 silver badges661 bronze badges
1 Answer
Reset to default 10The Indexed DB API does not provide a way to query the size of databases (or stores/indexes). Translating keys and values into bytes is also something performed by the browser and is not visible to script. So the script must be doing an approximation, e.g. puting the size of all keys and values in a store when serialized as strings.
The Indexed DB implementation in Chrome uses a backing store called leveldb which has various size optimizations, such as key prefix pression and value pression using another library called "snappy". Strings can also be serialized as bytes in numerous ways (e.g. JS strings are 16-bits per character, which could be naively stored as 2 bytes per character or UTF-8 encoded to 1-4 bytes per character). The backing store also lazily pacts when data is deleted or overwritten, so it may end up taking more space than it needs temporarily.
None of these optimizations are visible to script either, and all will vary cross browsers, so the approximation will be... approximate. Given all of this, an estimate of 389MB vs. the 255MB the browser reports is pretty good!
In Chrome we're experimenting with a per-type breakdown reported via the navigator.storage.estimate()
API that would give the exact value for each storage type (e.g. Indexed DB vs. Cache vs. ...), although it still would not give per-database or per-object store values.
本文标签: javascriptHow to calculate indexedDB table size in chromeStack Overflow
版权声明:本文标题:javascript - How to calculate indexedDB table size in chrome? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743980888a2571076.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论