Commit Graph

9 Commits

Author SHA1 Message Date
Agniva De Sarker
6a56af2a14 MM-30863: Fix race in LRU (#16382)
* MM-30863: Fix race in LRU

After shortening the critical section, we missed out the fact
that the byte slice is still accessible after the element is returned.
So the lock needs to be active until the byte slice is fully read and
unmarshaled

https://mattermost.atlassian.net/browse/MM-30863

```release-note
NONE
```

* incorporate suggestions

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2020-11-26 20:24:23 +05:30
Akshay Chhajed
26676953a4 MM-30140 LRU critical section optimization (#16184)
* MM-30140 LRU critical section optimization

* Remove empty line

* Renamed lru function
2020-11-20 11:29:27 +01:00
Agniva De Sarker
66731e2740 MM-29980: Optimize profilesInChannels cache to fast path (#16116)
* MM-29980: Optimize profilesInChannels cache to fast path

We add one more message type to the fast path- profiles in channels. There
are 2 primary reasons for this:

- This is not really a new model type, but just a map of users. And users already use
the fast path. So we can get some more gains without really investing much more code.
- A more important reason is that with the upcoming striped mutex changes, we will get
a higher throughput at the cost of a bit more CPU utilization. The reason being that
since less amount of time will be spent in lock-contention, the CPU is free to do more
stuff. So this change is to counter that increase.

As usual, this gives much better performance than the original decoder.

Micro-benchmark results
```
name               old time/op    new time/op    delta
LRU/UserMap=new-8    16.6µs ± 3%     3.9µs ± 4%  -76.15%  (p=0.000 n=10+10)

name               old alloc/op   new alloc/op   delta
LRU/UserMap=new-8    4.78kB ± 0%    2.74kB ± 0%  -42.65%  (p=0.000 n=10+10)

name               old allocs/op  new allocs/op  delta
LRU/UserMap=new-8      38.0 ± 0%      30.0 ± 0%  -21.05%  (p=0.000 n=10+10)
```

https://mattermost.atlassian.net/browse/MM-29980

Here are some results from a load test. The comparison is done with a 2 node cluster; one running master
and one running with this patch so that it's easier to compare. The total users are 2000.

<See PR>

```release-note
NONE
```

* Fix gofmt

* Trigger CI
2020-11-04 10:08:10 +05:30
Agniva De Sarker
91a76b2df9 MM-27456: Use reflect-free serialization for hot structs (#15171)
Automatic Merge
2020-08-13 03:35:57 -04:00
Siyuan Liu
c7f7bef9ec move cache2 package to cache (#14921)
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2020-07-18 13:31:06 +05:30
Agniva De Sarker
bfaf4fa5dc MM-22105: Revert "MM-21210: Add LRU cache for ChannelStore.GetMembersForUser (#13593)" (#13784)
This reverts commit 0361e8b97e.

The new cache ultimately did not give much benefit because the hit rate
was pretty low and it did not lead to any reduction in store timings.

So the increase in cluster messages was not worth it.

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-02-05 11:31:39 +05:30
Jesús Espino
06fb1458ca Use always strings for cache keys (#13631)
* Use always strings for cache keys

* fixing tests

* Addressing PR review comments

* Adding the base to FormatInt

* Fix typo
2020-01-22 15:59:59 +01:00
Agniva De Sarker
0361e8b97e MM-21210: Add LRU cache for ChannelStore.GetMembersForUser (#13593)
Automatic Merge
2020-01-13 10:46:51 -05:00
Hector
62b57143c8 [MM 19840] Create a Cache Interface abstraction to support multiple cache backends (#13384)
* Refactor to use structured logging

* Properly formatted with gofmt

* created interface Cache, but construction of cache is still coupled.

* Implementing cache factories to build caches

* Simple redis implementation without error handling. Keys and values by default are string

* refactor NewLocalCacheLayer to inject cache factory

* Removed redis impl to focus on cache abstraction

* CacheFactory injected on sqlsupplier and saved in Store struct

* remove useless private method

* replace concrete declaration of lru cache to cache abstraction

* discard spaces

* Renamed factory to provider because concrete implementations of factories may hold an state (such as a redis client for example)

* refactor to include all caches in the same package cache and subpackages

* method close cache. This method will be used for concrete implementations that need to release resources (close a connection, etc)

* closing cacheprovider and releasing resources while closing sql store

* fixed merge conflict fail

* gofmt files

* remove unused property from post_store

* naming refactor to avoid stutter. Added godocs on interface

* Store doesnt know anything about the cache and provider. Cache provider will be built after loading config and injected in localCacheLayer

* fixed broken test

* cache provider initialized before RunOldAppInitialization which initializes the localcachelayer

* move statusCache to server to initialize it with the new cache provider

* update terms_service and channel_layer to have new cacheProvider

* gofmt

* Add Connect method to the cache provider

* mock cacheprovider in user_layer_test

Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com>
Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-01-09 09:57:28 +01:00