mozilla / sccache

Sccache is a ccache-like tool. It is used as a compiler wrapper and avoids compilation when possible. Sccache has the capability to utilize caching in remote storage environments, including various cloud storage options, or alternatively, in local storage.
Apache License 2.0
5.74k stars 542 forks source link

`sccache` does not persist cache hit stats when server restart #2143

Open loynoir opened 6 months ago

loynoir commented 6 months ago

BUG

sccache does not persist cache hit stats when server stop

actual

When devcontainer restart, sccache restart.

sccache does not persist cache hit stats when server restart.

It leads to cache hit stats lost, all zero.

$ sccache --stop-server; sccache --start-server && sccache --show-adv-stats
...
Compile requests                      0
Compile requests executed             0
Cache hits                            0
Cache misses                          0
Cache timeouts                        0
Cache read errors                     0
Forced recaches                       0
Cache write errors                    0
Compilation failures                  0
Cache errors                          0
Non-cacheable compilations            0
Non-cacheable calls                   0
Non-compilation calls                 0
Unsupported compiler calls            0
Average cache write               0.000 s
Average compiler                  0.000 s
Average cache read hit            0.000 s
Failed distributed compilations       0
...

expected

sccache persist cache hit stats when server restart.

Keep cache stats across sccache restart.

sylvestre commented 6 months ago

Not sure it is a bug here. The cache is preserved, the stats aren't

loynoir commented 6 months ago

Yes, cache are preserved.

But when I happened to curious about the cache hit rate all these times, disappointedly, I found the cache hit rate stats are lost.

I think, it is a design bug, that I cannot see the history cache hit rate stats, since when I started to use sccache to now.


Hope a default option, or at least an opt-in config option, to persist cache hit rate stats.

https://github.com/mozilla/sccache/blob/a859c3b0bb501057b377a1a21171545909e5934e/src/config.rs#L346-L356

adv-stats-persist-path = 
loynoir commented 6 months ago

ccache does not have problem to see history cache hit rate stats, because ccache does not use client-server model.

Quote README.md

sccache works using a client-server model, where the server runs locally on the same machine as the client. The client-server model allows the server to be more efficient by keeping some state in memory.

So, there are two possibilities.


If client-server model is not very important


If client-server model is very important

sylvestre commented 5 months ago

Note that you can store the stats into a json file easily with --show-adv-stats --stats-format=json

As we don't have the use for persistent cache results (and I would not use it in general. I prefer to have stats per run of a project to easily see its impact or issues), I don't think we are going to spend time on it. So, PR welcome.

glandium commented 5 months ago

The client-server model has nothing to do with not keeping stats. The main blocker is that the main sccache use-case is to use a shared non-local cache. Persisting its stats is a challenge in itself.