Memory Usage

could someone please explain what might be causing the memory to continuously rise? I just have a single script running continuously but its not storing any new information.
No description
88 Replies
Percy
Percy11mo ago
Project ID: N/A
LargeEdition
LargeEditionOP11mo ago
N/A
LargeEdition
LargeEditionOP11mo ago
No description
Fragly
Fragly11mo ago
idk if it's just me, but I can't see the image you sent
LargeEdition
LargeEditionOP11mo ago
No description
Fragly
Fragly11mo ago
it's literally invisible
LargeEdition
LargeEditionOP11mo ago
wait gimme a sec lol
LargeEdition
LargeEditionOP11mo ago
No description
LargeEdition
LargeEditionOP11mo ago
its just this
LargeEdition
LargeEditionOP11mo ago
No description
LargeEdition
LargeEditionOP11mo ago
i deployed at 6PM I went on my website and clicked a button that ran one script continuously
Fragly
Fragly11mo ago
it's definitely something wrong with your script 🤔 what does your script do exactly
LargeEdition
LargeEditionOP11mo ago
it webscrapes a website given a runtime i set the script to run for 12 hours i set it to scrape a website every 10 minutes and on each iteration the only variable I change is i which increments the number of times the script has looped
Fragly
Fragly11mo ago
keep in mind webscraping is a somewhat gray area of Railway make sure the website you're scraping from is allowing webscraping and that you respect its robots.txt
LargeEdition
LargeEditionOP11mo ago
wdym by robots.txt where can i find a websites robots.txt
Fragly
Fragly11mo ago
each website has a robots.txt on its root example: https://youtube.com/robots.txt it tells robots what they can and can't do on any given website
Fragly
Fragly11mo ago
who wrote youtube's robots.txt 💀
No description
Fragly
Fragly11mo ago
anyway, the memory leak is very likely an issue with your code and not railway maybe whatever you're using to scrape has a memory leak in it
LargeEdition
LargeEditionOP11mo ago
the website im scraping doesn't have that webpage its just a scheduler for a school like where students can check if classes are open
Fragly
Fragly11mo ago
then it's all good
LargeEdition
LargeEditionOP11mo ago
oh ok but yea im still confused on what might be causing the gradual increase in ram usage it seems to be increasing by 1MB every 8 minutes bump
LargeEdition
LargeEditionOP11mo ago
No description
LargeEdition
LargeEditionOP11mo ago
it has now risen to almost 300MB i made sure to make sure all processes are completed but why is it still using 300MB? does someone have an explanation? i'm just trying to lower it to conserve costs
Brody
Brody11mo ago
I'm sorry but there's generally not all that much the community can do for you about a memory leak in your code, but lets do some basic debugging
LargeEdition
LargeEditionOP11mo ago
Oh so this is a memory leak?
Brody
Brody11mo ago
from your screenshot earlier I saw a ramp on the memory usage but either way, what kind of app is this
LargeEdition
LargeEditionOP11mo ago
its a script that sends an email when an element in a website updates
Brody
Brody11mo ago
how is it being ran
LargeEdition
LargeEditionOP11mo ago
wdym
Brody
Brody11mo ago
whats is the set start command?
LargeEdition
LargeEditionOP11mo ago
oh the script starts running on button click and it runs for a set amount of time (one of the inputs on my frontend)
Brody
Brody11mo ago
not quite what i asked lol
LargeEdition
LargeEditionOP11mo ago
sorry what do you mean by this then
Brody
Brody11mo ago
can you just send the repo instead?
LargeEdition
LargeEditionOP11mo ago
yea sure https://github.com/julianxchang/UCI_Class_Watcher wait i think its private gimme a sec public now
Brody
Brody11mo ago
the .env file 😐
LargeEdition
LargeEditionOP11mo ago
the script that is being ran is inside ye lol
Brody
Brody11mo ago
remove it lol
LargeEdition
LargeEditionOP11mo ago
gonna get rid of that
Brody
Brody11mo ago
going forward use a .gitignore file
LargeEdition
LargeEditionOP11mo ago
thats why i set it to private lol yea initially i had it but i didn't know how to deploy to railway without the .env
Brody
Brody11mo ago
never save secrets to your repo regardless of public or private
LargeEdition
LargeEditionOP11mo ago
LargeEdition
LargeEditionOP11mo ago
but yea the script being ran is here
LargeEdition
LargeEditionOP11mo ago
Ooo thanks I will take a look im thinking the memory leak is because I'm not setting driver = None after each loop? but I feel like that shouldn't matter because it should just overwrite driver after each iteration
Brody
Brody11mo ago
gotta delete these __pycache__ folders too
LargeEdition
LargeEditionOP11mo ago
what are these folders?
Brody
Brody11mo ago
cache folders
LargeEdition
LargeEditionOP11mo ago
they keep coming up after i debug locally
Brody
Brody11mo ago
you are using chrome in this app, given that fact, your memory usage isnt bad
LargeEdition
LargeEditionOP11mo ago
oh really?
Brody
Brody11mo ago
have you never seen a chrome memory usage meme??
LargeEdition
LargeEditionOP11mo ago
but the thing is when i deploy it started at around 140mb yea ive seen them before lol the thing is I do driver.quit() after each run so shouldn't the chrome instance stop
Brody
Brody11mo ago
but you do create a new driver on every loop, you dont need to do that
LargeEdition
LargeEditionOP11mo ago
Ooo could that be the issue? I think for better readability I might just make a function to create the chorme driver
Brody
Brody11mo ago
no clue, i dont do stuff with selenium as mostly what its used for is scraping and thats in railways tos
LargeEdition
LargeEditionOP11mo ago
oh shoot i see this is just a small project im testing to practice deployment
Brody
Brody11mo ago
youre just getting class info every 30 minutes right?
LargeEdition
LargeEditionOP11mo ago
i don't plan on having it up for long every 2 minutes i don't think interval should be issue tho since its performing the same task it just might use more vcpu
Brody
Brody11mo ago
to an extent is would be, im talking about if it breaks railways tos or not
LargeEdition
LargeEditionOP11mo ago
oh yea thats all im doing nothing more
Brody
Brody11mo ago
railway isnt going to care if you are looking at a site every 2 minutes, they would if you where looking at it every 2 miliseconds though
LargeEdition
LargeEditionOP11mo ago
oh yea i don't need to check that often haha but that would use a good amount of vcpu too no?
Brody
Brody11mo ago
a good amount of vcpu? 0.0 to 0.1 would be a good vcpu
LargeEdition
LargeEditionOP11mo ago
yea thats around what im getting rn
Brody
Brody11mo ago
but yeah just try to optimize your code, and if you want to drop your memory usage considerably, dont use a web browser lol
LargeEdition
LargeEditionOP11mo ago
No description
LargeEdition
LargeEditionOP11mo ago
oh btw all scripts have finished running and now its just consistently stuck at 300MB it seems like the memory usuage only goes up when a script is running
Brody
Brody11mo ago
prob still have chrome running
LargeEdition
LargeEditionOP11mo ago
ah ok ig i just have to add driver.quit() to the end once script stops wait...but I did hav that before tho...
Brody
Brody11mo ago
guess selenium isnt killing the chrome process
LargeEdition
LargeEditionOP11mo ago
Hmm
Brody
Brody11mo ago
do you even need to use a web browser to do this?
Brody
Brody11mo ago
no, it doesnt look like you do (ignore the no results, i dont have a clue what to put in to get a result but that doesnt matter)
No description
Brody
Brody11mo ago
make the request with the python request module, then parse the html in code with bs4
LargeEdition
LargeEditionOP11mo ago
Yea the problem is there’s no unique url for this website
Brody
Brody11mo ago
why does there need to be?
LargeEdition
LargeEditionOP11mo ago
I need to get specific element after entering specific inputs into website The url doesn’t change
Brody
Brody11mo ago
why does the url need to change?
LargeEdition
LargeEditionOP11mo ago
Cuz the page that I’m scraping isn’t this I reach the page after entering the class I want and clicking search for class button The page contents change but the url remains the same Hopefully that makes sense
Brody
Brody11mo ago
of course its not the same page you get, my page says no results
LargeEdition
LargeEditionOP11mo ago
Python requests isn’t able to click the button to load the new content tho Or am I missing sth
Brody
Brody11mo ago
why would you need to do that though, look at my screenshot, all im doing is giving the same data the web page gives itself in the end, its just form data, skip chrome and do that part yourself in code
LargeEdition
LargeEditionOP11mo ago
What are u using to see this page?
Brody
Brody11mo ago
thats postman, but theres nothing stopping you from doing the same in code ^
LargeEdition
LargeEditionOP11mo ago
Hmmm ok will look into this thx
Brody
Brody11mo ago
no problem
Want results from more Discord servers?
Add your server