# Dgraph slows down progressively

**URL:** <https://discuss.dgraph.io/t/dgraph-slows-down-progressively/6161>\
**Category:** Dgraph\
**Created:** [March 20, 2020, 9:52am UTC](https://discuss.dgraph.io/t/dgraph-slows-down-progressively/6161 "2020-03-20T09:52:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![myo](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/myo/32/872_2.png) [@myo](https://discuss.dgraph.io/u/myo)\
**Post date:** [March 20, 2020, 9:52am UTC](https://discuss.dgraph.io/t/dgraph-slows-down-progressively/6161/1 "2020-03-20T09:52:04Z")

</div>

Hello,

I just realised one of my DB regular cleaning operation was taking more and more time recently.

It consists of removing approx. 1700 edges on a predicate having @count and @reverse indexes, then re-adding them.

Recently it took 1 minute each which seemed very slow to me.

I tried to export my base, stop dgraph, remove DB files, start dgraph, import my base and finally try again my operations, and they took 5 et 9 seconds!

What is happening in Dgraph database to get progressively slower?

Dgraph version: 1.2.1, CPU: i7-7700HQ CPU @ 2.80GHz, RAM: 16Gb DDR3

---

<div class="post-metadata">

**Author:** ![arijit](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/arijit/32/2116_2.png) [@arijit](https://discuss.dgraph.io/u/arijit)\
**Post date:** [March 27, 2020, 3:14pm UTC](https://discuss.dgraph.io/t/dgraph-slows-down-progressively/6161/2 "2020-03-27T15:14:11Z")

</div>

I added around 100k edges and I tried removing and adding 1700 edges on a predicate with @reverse and @count indexes.  
It’s taking around 14sec. Could you try running this at your end and let me know how much time it takes?

```auto
func TestCountIndexThroughput(t *testing.T) {
	total := 100000
	numUIDs := uint64(total)

	dg, err := testutil.DgraphClientWithGroot(testutil.SockAddr)
	if err != nil {
		t.Fatalf("Error while getting a dgraph client: %v", err)
	}

	if err := testutil.AssignUids(uint64(total * 10)); err != nil {
		t.Fatalf("error in assigning UIDs :: %v", err)
	}

	rdfs := make([]string, 0)
	for uid := 1; uid < int(numUIDs); uid++ {
		rdf := fmt.Sprintf("<%v> <friend> <%v> .\n", uid, uid+1)
		if err := testutil.RetryMutation(dg, &api.Mutation{
			CommitNow: false,
			SetNquads: []byte(rdf),
		}); err != nil {
			t.Fatalf("error in mutation :: %v", err)
		}
		rdfs = append(rdfs, rdf)
	}

	start := time.Now()
	for idx, rdf := range rdfs {
		if err := testutil.RetryMutation(dg, &api.Mutation{
			CommitNow: false,
			DelNquads: []byte(rdf),
		}); err != nil {
			t.Fatalf("error in mutation :: %v", err)
		}
		if idx > 1700 {
			break
		}
	}

	for idx, rdf := range rdfs {
		if err := testutil.RetryMutation(dg, &api.Mutation{
			CommitNow: false,
			SetNquads: []byte(rdf),
		}); err != nil {
			t.Fatalf("error in mutation :: %v", err)
		}
		if idx > 1700 {
			break
		}
	}
	elapsed := time.Since(start)
	log.Printf("Time: %s", elapsed)
}

```

---

<div class="post-metadata">

**Author:** ![myo](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/myo/32/872_2.png) [@myo](https://discuss.dgraph.io/u/myo)\
**Post date:** [March 27, 2020, 3:43pm UTC](https://discuss.dgraph.io/t/dgraph-slows-down-progressively/6161/3 "2020-03-27T15:43:06Z")

</div>

Hello, where do I find your `testutil` package, and how should I use it?

---

<div class="post-metadata">

**Author:** ![arijit](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/arijit/32/2116_2.png) [@arijit](https://discuss.dgraph.io/u/arijit)\
**Post date:** [March 27, 2020, 3:53pm UTC](https://discuss.dgraph.io/t/dgraph-slows-down-progressively/6161/4 "2020-03-27T15:53:06Z")

</div>

I wrote this code in dgraph/query/mutation\_test.go but you can use the dgo([GitHub - dgraph-io/dgo: Official Dgraph Go client](https://github.com/dgraph-io/dgo)) client as well.

---

<div class="post-metadata">

**Author:** ![myo](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/myo/32/872_2.png) [@myo](https://discuss.dgraph.io/u/myo)\
**Post date:** [April 7, 2020, 6:16am UTC](https://discuss.dgraph.io/t/dgraph-slows-down-progressively/6161/5 "2020-04-07T06:16:53Z")

</div>

Hello,  
I don’t have the slowdown anymore. When I reset my test database I now use a bulk import, instead of a clear alter & live import. It’s like if the clear op doesn’t clear everything. I’m also on 1.2.2 now.  
Thank you anyway.
