-
Notifications
You must be signed in to change notification settings - Fork 12
ConfigurationCaching
The service maintains the following runtime caches:
Cache name | Description |
---|---|
gists | holds responses returned by /gists/{gistid} and /{gistId}/{commitId} GET endpoints |
comments | holds responses returned by /gists/{gistId}/comments and /gists/{gistId}/comments/{commentId} GET endpoints |
commentstore | cache for a comment store |
metadatastore | cache for a metadata store |
historystore | caches commits extracted from gist (git) repository |
filecontentcache | caches content of files stored in gist (git) repository |
sessionkeys | caches authenticated session keys |
Default configuration of caches is located in application.yml and it looks like this:
caches:
-
name: 'sessionkeys'
evictionPolicy: LRU
ttl: 60
maxSize: 100
maxIdleSeconds: 60
-
name: 'gists'
evictionPolicy: LRU
ttl: 300
maxSize: 200
maxIdleSeconds: 300
-
name: 'comments'
evictionPolicy: LRU
ttl: 300
maxSize: 200
maxIdleSeconds: 300
-
name: 'commentstore'
evictionPolicy: LRU
ttl: 300
maxSize: 200
maxIdleSeconds: 300
-
name: 'metadatatore'
evictionPolicy: LRU
ttl: 300
maxSize: 200
maxIdleSeconds: 300
-
name: 'historystore'
evictionPolicy: LRU
ttl: 300
maxSize: 200
maxIdleSeconds: 300
-
name: 'filecontentcache'
evictionPolicy: LRU
ttl: 300
maxSize: 200
maxIdleSeconds: 300
Each cache has the following properties:
Property | Description | Accepted Values |
---|---|---|
evictionPolicy | which entries should be deleted if eviction of elements is requested | NONE (no eviction), LRU (Least Recently Used), LFU (Least Frequently Used) |
ttl | (time to live) Maximum number of seconds for each entry to stay in the cache. Entries that are older than ttl value and not updated for ttl will get automatically evicted |
Integer between 0 and Integer.MAX_VALUE. Zero means infinite. |
maxSize | Maximum number of elements in the cache. When maxSize is reached, elements are evicted using the evictionPolicy
|
Integer between 0 and Integer.MAX_VALUE. Zero means Integer.MAX_VALUE. |
maxIdleSeconds | Maximum number of seconds for each entry to stay idle in the map. Entries that are not touched (idle) for more than the specified amount of time will get evicted | Integer between 0 and Integer.MAX_VALUE. Zero means infinite. |
To change the cache configuration add the caches
element to /opt/rcloud-gist-service/application.yml
with all caches configurations, and modify properties of the caches that you wish to override.
Note - you need to include all caches configuration, even if you just want to change settings of a single element. If not, the changes won't take an effect.
To change default settings of filecontentcache
, so maxIdleSeconds
and ttl
is 300000
seconds, add the following section to /opt/rcloud-gist-service/application.yml
file:
caches:
-
name: 'sessionkeys'
evictionPolicy: LRU
ttl: 60
maxSize: 100
maxIdleSeconds: 60
-
name: 'gists'
evictionPolicy: LRU
ttl: 300
maxSize: 200
maxIdleSeconds: 300
-
name: 'comments'
evictionPolicy: LRU
ttl: 300
maxSize: 200
maxIdleSeconds: 300
-
name: 'commentstore'
evictionPolicy: LRU
ttl: 300
maxSize: 200
maxIdleSeconds: 300
-
name: 'metadatatore'
evictionPolicy: LRU
ttl: 300
maxSize: 200
maxIdleSeconds: 300
-
name: 'historystore'
evictionPolicy: LRU
ttl: 300
maxSize: 200
maxIdleSeconds: 300
-
name: 'filecontentcache'
evictionPolicy: LFU
ttl: 30000
maxSize: 2000
maxIdleSeconds: 30000
You need to restart the service for the changes to take an effect.
The service uses Hazelcast as cache implementation. Hazelcast configuration is located at hazelcast.xml
The configuration results in a standalone hazelcast instance with a default
map configuration, which all caches used by the service extend:
<map name="default">
<!--
Data type that will be used for storing recordMap.
Possible values:
BINARY (default): keys and values will be stored as binary data
OBJECT : values will be stored in their object forms
NATIVE : values will be stored in non-heap region of JVM
-->
<in-memory-format>BINARY</in-memory-format>
<!--
Number of backups. If 1 is set as the backup-count for example,
then all entries of the map will be copied to another JVM for
fail-safety. 0 means no backup.
-->
<backup-count>1</backup-count>
<!--
Number of async backups. 0 means no backup.
-->
<async-backup-count>0</async-backup-count>
<!--
Maximum number of seconds for each entry to stay in the map. Entries that are
older than <time-to-live-seconds> and not updated for <time-to-live-seconds>
will get automatically evicted from the map.
Any integer between 0 and Integer.MAX_VALUE. 0 means infinite. Default is 0.
-->
<time-to-live-seconds>300</time-to-live-seconds>
<!--
Maximum number of seconds for each entry to stay idle in the map. Entries that are
idle(not touched) for more than <max-idle-seconds> will get
automatically evicted from the map. Entry is touched if get, put or containsKey is called.
Any integer between 0 and Integer.MAX_VALUE. 0 means infinite. Default is 0.
-->
<max-idle-seconds>300</max-idle-seconds>
<!--
Valid values are:
NONE (no eviction),
LRU (Least Recently Used),
LFU (Least Frequently Used).
NONE is the default.
-->
<eviction-policy>LFU</eviction-policy>
<!--
Maximum size of the map. When max size is reached,
map is evicted based on the policy defined.
Any integer between 0 and Integer.MAX_VALUE. 0 means
Integer.MAX_VALUE. Default is 0.
-->
<max-size policy="PER_NODE">1000</max-size>
<!--
When max. size is reached, specified percentage of
the map will be evicted. Any integer between 0 and 100.
If 25 is set for example, 25% of the entries will
get evicted.
-->
<eviction-percentage>25</eviction-percentage>
<!--
Minimum time in milliseconds which should pass before checking
if a partition of this map is evictable or not.
Default value is 100 millis.
-->
<min-eviction-check-millis>100</min-eviction-check-millis>
<!--
While recovering from split-brain (network partitioning),
map entries in the small cluster will merge into the bigger cluster
based on the policy set here. When an entry merge into the
cluster, there might an existing entry with the same key already.
Values of these entries might be different for that same key.
Which value should be set for the key? Conflict is resolved by
the policy set here. Default policy is PutIfAbsentMapMergePolicy
There are built-in merge policies such as
com.hazelcast.map.merge.PassThroughMergePolicy; entry will be overwritten if merging entry exists for the key.
com.hazelcast.map.merge.PutIfAbsentMapMergePolicy ; entry will be added if the merging entry doesn't exist in the cluster.
com.hazelcast.map.merge.HigherHitsMapMergePolicy ; entry with the higher hits wins.
com.hazelcast.map.merge.LatestUpdateMapMergePolicy ; entry with the latest update wins.
-->
<merge-policy>com.hazelcast.map.merge.PutIfAbsentMapMergePolicy</merge-policy>
<!--
Control caching of de-serialized values. Caching makes query evaluation faster, but it cost memory.
Possible Values:
NEVER: Never cache deserialized object
INDEX-ONLY: Caches values only when they are inserted into an index.
ALWAYS: Always cache deserialized values.
-->
<cache-deserialized-values>INDEX-ONLY</cache-deserialized-values>
</map>
The map configuration specifies a PER_NODE
policy for controlling the maximum size of caches. This policy results in the maxSize
property to specify the maximum number of elements allowed in each cache.
In case the PER_NODE
policy does not suite the service usage scheme, there are other policies available MaxSizeConfig.MaxSizePolicy
Note, changing policy affects all caches used by the service. Controlling the policy on per-cache basis is not currently supported.
In order to change the maxSize
policy of caches used by the service, the following actions need to be performed:
-
hazelcast.xml
configuration needs to be placed in/opt/rcloud-gist-service
- the
policy
attribute of themax-size
element in themap
element needs to be updated to required policy, e.g.:
<map>
[...]
<max-size policy="FREE_HEAP_PERCENTAGE">20</max-size>
[...]
</map>
- Caches configuration in
/opt/rcloud-gist-service/application.yml
need to be customized, so theirmaxSize
property values are valid for the new policy, e.g.:
[...]
caches:
-
name: 'sessionkeys'
evictionPolicy: LRU
ttl: 60
maxSize: 10
maxIdleSeconds: 60
-
name: 'gists'
evictionPolicy: LRU
ttl: 10
maxSize: 20
maxIdleSeconds: 10
-
name: 'comments'
evictionPolicy: LRU
ttl: 10
maxSize: 20
maxIdleSeconds: 10
-
name: 'commentstore'
evictionPolicy: LRU
ttl: 10
maxSize: 20
maxIdleSeconds: 10
-
name: 'metadatatore'
evictionPolicy: LRU
ttl: 10
maxSize: 20
maxIdleSeconds: 10
-
name: 'historystore'
evictionPolicy: LRU
ttl: 10
maxSize: 20
maxIdleSeconds: 10
-
name: 'filecontentcache'
evictionPolicy: LRU
ttl: 300000
maxSize: 20
maxIdleSeconds: 300000
[...]
- restart the service
The example above, will result in caches which elements are evicted when the available free heap memory of the service drops to 20%.