# Fdb taking around 15 ms to clear 1 single key

**URL:** <https://forums.foundationdb.org/t/fdb-taking-around-15-ms-to-clear-1-single-key/3705>\
**Category:** Using FoundationDB\
**Tags:** performance\
**Created:** [December 22, 2022, 6:08pm UTC](https://forums.foundationdb.org/t/fdb-taking-around-15-ms-to-clear-1-single-key/3705 "2022-12-22T18:08:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sandeep-nallapu](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/sandeep-nallapu/32/1484_2.png) [@sandeep-nallapu](https://forums.foundationdb.org/u/sandeep-nallapu)\
**Post date:** [December 22, 2022, 6:08pm UTC](https://forums.foundationdb.org/t/fdb-taking-around-15-ms-to-clear-1-single-key/3705/1 "2022-12-22T18:08:16Z")

</div>

I am clearing some keys with a big range. approximately 1000 gb. The clear operation for every key is taking around 15 milliseconds. which is quite high because I have 170 million keys and it takes around 2 weeks to clear all the keys. Any help on how to make it faster?

---

<div class="post-metadata">

**Author:** ![Imperatorx](https://avatars.discourse-cdn.com/v4/letter/i/d2c977/32.png) [@Imperatorx](https://forums.foundationdb.org/u/Imperatorx)\
**Post date:** [December 22, 2022, 7:48pm UTC](https://forums.foundationdb.org/t/fdb-taking-around-15-ms-to-clear-1-single-key/3705/2 "2022-12-22T19:48:46Z")

</div>

Delete them in a single clear(Range) operation, if the keys form a continuous range.

If not, delete them in parallel, e.g. partition the huge key list to 100 smaller list, start 100 threads and process each sub-list concurrently.

---

<div class="post-metadata">

**Author:** ![markus.pilman](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/markus.pilman/32/379_2.png) [@markus.pilman](https://forums.foundationdb.org/u/markus.pilman)\
**Post date:** [December 22, 2022, 11:00pm UTC](https://forums.foundationdb.org/t/fdb-taking-around-15-ms-to-clear-1-single-key/3705/3 "2022-12-22T23:00:45Z")

</div>

The bottleneck you have is not the actual deletion but the commit pipeline. In addition to what @Imperatorx said, you probably should have more than one clear in each transaction. That way you pay less for the commit (though you don’t want to make the transaction huge either – I would probably try to make each transaction ~10-100KB in size – you can estimate the size by adding adding up the size of the key ranges)

---

<div class="post-metadata">

**Author:** ![sandeep-nallapu](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/sandeep-nallapu/32/1484_2.png) [@sandeep-nallapu](https://forums.foundationdb.org/u/sandeep-nallapu)\
**Post date:** [December 24, 2022, 5:38pm UTC](https://forums.foundationdb.org/t/fdb-taking-around-15-ms-to-clear-1-single-key/3705/4 "2022-12-24T17:38:18Z")

</div>

Yes, I am deleting them in a single range operation but its difficult to track how much data we are clearing when deleting a range. I think there should be a way to track how much data for range too. Previously I was adding len(key.bytes) for each key deletion.

---

<div class="post-metadata">

**Author:** ![hbs](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/hbs/32/1419_2.png) [@hbs](https://forums.foundationdb.org/u/hbs)\
**Post date:** [January 2, 2023, 11:03am UTC](https://forums.foundationdb.org/t/fdb-taking-around-15-ms-to-clear-1-single-key/3705/6 "2023-01-02T11:03:02Z")

</div>

You can estimate the size in bytes of data within a key range using the `getEstimatedRangeSizeBytes` API.
