R studio RAM & CPU usage spikes every time I save script


#1

I have a script that does a range of things: pull data from SQL server, manipulations using data.table & custom packages, parallel processing using Rcpp, etc. When R is idle & I hold some large data.tables in memory, i type something into the script just to activate the save button, undo the addition, save the script, and suddenly the RAM & CPU usage spikes and eventually settles to something nearly 50% higher. I just also noticed that in fact the CPU & RAM usage spikes as soon as I type into the script! When I do gc(), the RAM returns to previous level. Please let me know what information I should provide to identify the problem. Any help/advice would be greatly appreciated!

I should also say I ran into this problem only recently. I updated R to 3.5, then I reverted back to 3.4 as I couldn't get Rtools to work. Hope this helps.


#2

i'd really appreciate some help on this please. i have reinstalled rstudio and upgraded packages too. no idea what's up.


#3

Can you by any chance provide a reproducible example?

Just to confirm, is it the rsession process itself that's consuming RAM + CPU, or is it a sub-process launched by the R session (or even, the RStudio front-end process)? Does the task manager report this in any granularity? Does the R session remain responsive when this CPU usage spike happens, or is it frozen for a short amount of time?


#4

do you know what CPU you have and how much RAM?


#5

Hi Kevin, thanks for your response.

Just to confirm, is it the rsession process itself that's consuming RAM + CPU, or is it a sub-process launched by the R session (or even, the RStudio front-end process)? -- I see "R Studio R session" under "Background Processes" in Task Manager consume the RAM and CPU.

Does the task manager report this in any granularity? -- I see R Studio under "Apps" and "R Studio R session" under background processes only. I don't see further detail relevant to R. Let me know if you need me to look somewhere specifically however.

Does the R session remain responsive when this CPU usage spike happens, or is it frozen for a short amount of time? -- I run a command from the console when the RAM & CPU spike and it looks like it gets queued to execute. The application however is not frozen per say, I am still able to type and move around only there is delay in execution. So, for example, gc() from console waits until the spike is complete and then runs, same delay happens if I save script, it gets done when the spike is complete.

Here is a simple example but it does not cause jumps in RAM & CPU. In the main script however, doing stuff like this starts causes the jumps:

'library(data.table)

dt<-data.table(a=rep(1:5),b=runif(10000000))

dt<-data.table(setid=dt[a %in% c(1,5),a][rep(seq_len(.N),each=2)])

dt.final<-rbindlist(list(dt,dt))'

Let me know if you need me to run something on my machine and give some output to help.


#6

I have 32gb RAM & Intel Xeon E5-2690 v3. It is setup as a virtual computer and resources are shared with other people however everyone else is disconnected.


#7

You could try running an R profile to see if there's some R code being executed in the main session that's causing the lag. Try running:

Rprof("rstudio-trace.Rprof")

Then, work in the IDE for a bit until the lag occurs. After that, call

Rprof(NULL)

and then share the contents of that file, or try interpreting summaryRprof("rstudio-trace.Rprof") to see if anything stands out in there.