openwhisk icon indicating copy to clipboard operation
openwhisk copied to clipboard

delete old activations doesn't free disk space

Open jiangpengcheng opened this issue 8 years ago • 16 comments

the delete in couchdb is an update actually, so it will increase the usage of disk space, and while the purge is not implemented in couchdb right now, looks like we have no way to free the disk space

I do a test to insert 10 millions documents to couchdb, and delete them later, below is my test result:

before insert:

root@bf83420db0ec:/opt/couchdb# du -h --max-depth=1
64K    ./bin
5.8M    ./erts-6.2
40K    ./etc
19M    ./lib
244K    ./releases
3.2M    ./share
0      ./var
7.5M    ./data
36M    .

after insert 10 millions documents:

root@bf83420db0ec:/opt/couchdb# du -h --max-depth=1
64K    ./bin
5.8M    ./erts-6.2
40K    ./etc
19M    ./lib
244K    ./releases
3.2M    ./share
0      ./var
2.1G    ./data
2.2G    .

after create the activations/byDate view:

root@bf83420db0ec:/opt/couchdb# du -h --max-depth=1
64K    ./bin
5.8M    ./erts-6.2
40K    ./etc
19M    ./lib
244K    ./releases
3.2M    ./share
0      ./var
4.6G    ./data
4.6G    .

after delete all test documents(the used space increase)

root@bf83420db0ec:/opt/couchdb# du -h --max-depth=1
64K    ./bin
5.8M    ./erts-6.2
40K    ./etc
19M    ./lib
244K    ./releases
3.2M    ./share
0      ./var
6.9G    ./data
6.9G    .

after compact db

root@bf83420db0ec:/opt/couchdb# du -h --max-depth=1
64K    ./bin
5.8M    ./erts-6.2
40K    ./etc
19M    ./lib
244K    ./releases
3.2M    ./share
0      ./var
4.5G    ./data
4.5G    .

after compact view

root@bf83420db0ec:/opt/couchdb# du -h --max-depth=1
64K    ./bin
5.8M    ./erts-6.2
40K    ./etc
19M    ./lib
244K    ./releases
3.2M    ./share
0      ./var
2.3G    ./data
2.3G    .

So even after compact the db and view, the usage of disk size doesn't reduce a lot(it is bigger instead)

I know this is related to couchdb, but I wonder if there are someone has some experience to solve this problem.

This can be a problem in the production environment as the used disk size will keep growing

jiangpengcheng avatar Dec 07 '17 01:12 jiangpengcheng

@cbickel do we have a compaction script?

@jiangpengcheng you are right - you need to compact the db; see http://docs.couchdb.org/en/2.1.1/maintenance/compaction.html.

rabbah avatar Dec 07 '17 01:12 rabbah

Even after doing a purge follow by a compact, disk size will not shrink as docs are never deleted.

_purge

Purging documents does not remove the space used by them on disk. To reclaim disk space, you should run a database compact (see /db/_compact), and compact views (see /db/_compact/design-doc).

with compat you are removing old revisions, so not a complete delete _compat

Writes a new, optimised, version of the database file, removing any unused sections from the new version during write. Because a new file is temporarily created for this purpose, you may require up to twice the current storage space of the specified database in order for the compaction routine to complete.
Removes old revisions of documents from the database, up to the per-database limit specified by the _revs_limit database parameter.

If you want to really delete docs, for example old activations that you don't care about them after certain period you would need to use a new db, and replicate docs you really want to keep.

There are a few blogs around the web that talk about this: https://eclipsesource.com/blogs/2015/04/20/how-to-finally-delete-documents-in-couchdb/

For whisk db holding docs for entities like actions, then purge and compat are more effective, deleting old history.

csantanapr avatar Dec 07 '17 02:12 csantanapr

yes, it seems _purge will work well, but _purge is not implemented by now: https://github.com/apache/couchdb/issues/965

and replace the activations db need about 1 second to finish, this may cause error during that period

jiangpengcheng avatar Dec 07 '17 03:12 jiangpengcheng

Ah thanks for pointing out the _purge item, I thought I saw purge long time ago in some couchdb docs in 1.x maybe I confused them with compat

What 1 second are you talking about and what errors?

In production we do blue/green swap to avoid downtime period and avoid errors.

csantanapr avatar Dec 07 '17 05:12 csantanapr

ok, I understand now, thanks a million!

1 second is mean: we delete the old activation database and create a new one using same name, this need about 1 second to finish, and during that time the activation database is not exist, that is the error.

By using blue/green deployment we can avoid that error

jiangpengcheng avatar Dec 07 '17 05:12 jiangpengcheng

Oh never delete the active db, create a new db with a new name, once you move all components to the new db, then you can go back and delete the old db and start reclaiming disk space.

csantanapr avatar Dec 07 '17 05:12 csantanapr

ok, I get that now, thanks again 😄

jiangpengcheng avatar Dec 07 '17 05:12 jiangpengcheng

@csantanapr How do you manage such procedures without any service shutdown?

style95 avatar Dec 07 '17 05:12 style95

@style95 You have to replicate the documents of your current database (e.g wsk_activations) to a second database (e.g. wsk_activations1). When the replication is finished, you can change db_whisk_activations in ansible to the new database activations1. After a redeployment of the system, the new database will be used and you can delete the old database.

cbickel avatar Dec 07 '17 07:12 cbickel

@cbickel Could you redeploy your system under high load as well? Do you have logics for zero downtime deployment or blue-green deployment?

style95 avatar Dec 07 '17 07:12 style95

As Carlos mentioned, we have a blue-green deployment. The load will go to blue, while green will be updated. After the update is complete we route the load to green and update blue.

cbickel avatar Dec 07 '17 07:12 cbickel

below is my thought with rolling update deployment:

  1. create continuous replication of activations database with selector:
{
   ...
   "selector": {
      "start": {
        "$gte": "1512630323343"
      }
    }
   ...
}
  1. create new replication from new database to old one, then the replication is bidirectional

  2. configure new deployment using new activation database

  3. start deployment, the new component will use new database, and old ones still use old database, as the two database are replicated between each other, so it's ok to use different database

  4. after deployment is over, the old database is useless, we can delete it

jiangpengcheng avatar Dec 07 '17 07:12 jiangpengcheng

In opensource OpenWhisk, blue-green deployment is not supported yet, right?

style95 avatar Dec 07 '17 08:12 style95

blue-green should be supported, but everyone would have specific requirements based how they deploy. I don’t have a problem if someone wants to contribute a doc sectio/paragraph in the ansible readme capturing a simple/based blue-green scenario. The end results boils down having two environments definitions and some type of top level nginx/router/gateway to drain and switch traffic.

csantanapr avatar Dec 07 '17 12:12 csantanapr

another problem is: the growth of disk usage may be very fast, it can be hundreds of GB per day if the tps up to 10,000(this value is not high if cluster hosting many services), we don't want to redeploy frequently, right?

jiangpengcheng avatar Dec 13 '17 02:12 jiangpengcheng

It could certainly grow - the metadata is small (< 1KB) but the result and logs could be MBs large in all. We are doing and discussing the following to reduce the load on the db: 1. Stop creating rule activation records and only create trigger activations if they cause actions to execute, 2. Possibly drop the trigger activation altogether in the future, 3. Retain logs in a seperate store with a much shorter retention and defer to a stack like ELK for longer longevity.

rabbah avatar Dec 13 '17 12:12 rabbah