Comments (13)
If I look at the "Year" activity which is disabled in the web-ui by default and refresh that a few times it grows to around 1.1GB of RAM usage and stops there...
from aw-server-rust.
Seems to be SQLite doing some caching, seems to be possible to configure it to not cache as much in memory with different PRAGMAs.
==659099== 2,105,376 bytes in 482 blocks are possibly lost in loss record 285 of 285
==659099== at 0x483977F: malloc (vg_replace_malloc.c:309)
==659099== by 0x3FF26A: sqlite3MemMalloc (sqlite3.c:23057)
==659099== by 0x3FFB61: mallocWithAlarm (sqlite3.c:26889)
==659099== by 0x3FFC39: sqlite3Malloc (sqlite3.c:26919)
==659099== by 0x40EAA7: pcache1Alloc (sqlite3.c:49204)
==659099== by 0x40ECEA: pcache1AllocPage (sqlite3.c:49301)
==659099== by 0x40F7CB: pcache1FetchStage2 (sqlite3.c:49768)
==659099== by 0x40F932: pcache1FetchNoMutex (sqlite3.c:49872)
==659099== by 0x40F97B: pcache1FetchWithMutex (sqlite3.c:49887)
==659099== by 0x40F9D4: pcache1Fetch (sqlite3.c:49910)
==659099== by 0x40DBF5: sqlite3PcacheFetch (sqlite3.c:48353)
==659099== by 0x4155DF: getPageNormal (sqlite3.c:56269)
from aw-server-rust.
I don't think it's SQLite anymore, it was only partial loss of 2MB which is nothing.
Seems to be something when cloning Events.
from aw-server-rust.
This is likely the issue
https://doc.rust-lang.org/nomicon/leaking.html#drain
from aw-server-rust.
I've read that and think I somewhat understand the issue, but what would a fix look like in our case?
from aw-server-rust.
Alright, just realized that it's not drain either.
I made this example program to reproduce the issue
use std::io::Write;
trait New {
fn new() -> Self;
}
#[derive(Clone)]
struct StackType {
num: i64
}
impl New for StackType {
fn new() -> Self {
Self { num: 0 }
}
}
#[derive(Clone)]
struct HeapType {
num: Box<i64>
}
impl New for HeapType {
fn new() -> Self {
Self { num: Box::new(0) }
}
}
const N : usize = 10000000;
fn alloc<T: New + Clone>() {
let _vec : Vec<T> = vec![T::new(); N];
}
pub fn wait_for_enter(prompt: &str) {
print!("{}", prompt);
std::io::stdout().flush().unwrap();
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
}
fn main() {
println!("Alloc stack");
alloc::<StackType>();
wait_for_enter("Dropped vec with stack allocated variables, press enter to continue");
println!("Alloc heap");
alloc::<HeapType>();
wait_for_enter("Dropped vec with heap allocated variables, press enter to quit");
}
Allocations on the stack get freed instantly and the allocations on the heap are not returned.
Apparently it seems like it's due to how malloc in glibc works
Not sure what we should do about it though, or if we should do anything about it at all.
from aw-server-rust.
Shouldn't be a problem then? And looks like we can't really do anything about it anyway.
from aw-server-rust.
Would be interesting to see how windows and mac handles this.
from aw-server-rust.
#118 seems to improve it slightly and #119 would likely pretty much fix it.
Seems like we are simply allocating/deallocating so much memory during a short period of time when doing queries that the allocator finds it to be a good idea to not release memory to the kernel. Reducing the amount of memory copying seems to improve things.
from aw-server-rust.
Another way to solve this is to use jemalloc (default for rust in 2018) instead of malloc (the default for rust today in 2020).
It works a bit differently, it grows quickly to around 200-300MB when doing many month queries for me, but after that it doesn't grow anymore but releases the memory to the kernel.
That it's 200-300MB is probably because of how many events I'm querying and since I'm not on the computer I spend the most time on I'm sure it will go higher on other databases with more events during a month.
Maybe we should do that until the root cause is fixed as a temporary solution? To do that we need to add the jemallocator dependency and 3 lines of code.
from aw-server-rust.
@johan-bjareholt Sounds good to me.
If you are consistently measuring significantly improved memory management by jemalloc then it sounds like a good idea in general.
from aw-server-rust.
Well, that didn't go as planned...
warning: "jemalloc support for
x86_64-pc-windows-msvc
is untested"
Could test if the slow freeing of memory also occurs on windows, if it doesn't we could only enable jemalloc on Linux. I'd like to avoid platform specific dependencies, but I still think it's worth it.
from aw-server-rust.
I merged it only for Linux for now. #144
We'll see if it's an issue just for Linux or for the default allocators in Windows/macOS as well.
I'll close this issue and create a new issue for simply lowering the RAM usage.
from aw-server-rust.
Related Issues (20)
- Persist settings to server HOT 8
- Pins cpu usage at 100% HOT 4
- Major data loss -- server doesn't appear to write data to disk properly HOT 2
- Called `Option::unwrap()` on a `None` value HOT 2
- No log file found on startup
- Error loading common words in "Uncategorized events"
- No rule to make target 'build' HOT 1
- "poisoned lock: another task failed inside" HOT 6
- This is really a great project. I would like to help you with some functionalities. Please let me know where to start. HOT 4
- database upgrade causes all data lost HOT 4
- Encryption at rest for database files HOT 1
- Error: No db found in sync folder HOT 3
- Possible database corruption and 100% CPU after Windows updates
- aw-sync old libssl dependency HOT 2
- Missing license file in mpsc_requests-0.3.3.crate HOT 8
- Suggestion: Regex-based inbound data filters HOT 4
- Add `!local` special hostname when creating buckets (for aw-server-python parity) HOT 1
- Add more options to aw-sync daemon
- Suggestion: Optimizing the Database
- Add webhooks
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aw-server-rust.