VITAS changed the topic of #spacedock to: Problems?: https://github.com/KSP-SpaceDock/SpaceDock/issues | Matrix/Riot Chat: https://im.52k.de +spacedock:52k.de Feel free to ask for help, we only bite a little bit! | If you want to help, please check https://github.com/KSP-SpaceDock/SpaceDock-Backend/issues/5 :) | <VITAS> inet users have the attentionspan of a squirrel...
HebaruSan[m] has joined #spacedock
<HebaruSan[m]> b.py is missing `from .a import this_is_global`
<HebaruSan[m]> And it doesn't need the `global` statement
<HebaruSan[m]> That's how all modules work
<HebaruSan[m]> `touch __init__.py`
<HebaruSan[m]> Oh, it'll give you a circular import error when you get that set up
<HebaruSan[m]> So don't do it that way 😉
<HebaruSan[m]> That's the point of having a `cache.py` module, it doesn't need to import any of the other stuff
<HebaruSan[m]> It's a leaf in the dependency tree
<HebaruSan[m]> I'll take a stab at setting up flask_caching as I understand it if I can find the time
<HebaruSan[m]> Hence <span class="d-mention d-user">DasSkelett</span> trying repeatedly to get your guys' attention with a suggestion to fix that 🙂
<HebaruSan[m]> `recent` looks like it might be even slower, it's not just hitting every mod, it's hitting every mod VERSION
<HebaruSan[m]> Guys don't worry about `current_app`, there's another way of doing it
<HebaruSan[m]> But to get that count it tests `ModVersion.mod_id == Mod.id` for every ModVersion
<HebaruSan[m]> Maybe there's some automatic indexing
<HebaruSan[m]> `/browse/top` uses different logic than the 'top' section of `/<gameshort>`
<HebaruSan[m]> But it doesn't worry about scores, it just has the db sort by descending download count
<HebaruSan[m]> Whereas `/browse/top` calls `search_mods` which gets the list from the db and then applies its own custom sort
<HebaruSan[m]> I'm not blaming the db, I'm blaming the custom sort
<HebaruSan[m]> Hypothetically if we sped up search_mods, would anything be left that's dramatically slow?
<HebaruSan[m]> Because I was just fleshing out a flask_caching prototype and realized that the rest of it should be pretty quick
<HebaruSan[m]> <span class="d-mention d-user">Darklight</span> can you please try switching to this branch and let me know if it crashes? I don't recall the commands to set up a dummy SpaceDock, and you have a good testbed with lots of dummy data.
<HebaruSan[m]> Oh, I probably need to make it install flask_caching, one moment...
<HebaruSan[m]> Pushed a new commit to update requirements-backend.txt
<HebaruSan[m]> You know, if we just did what <span class="d-mention d-user">DasSkelett</span> suggested and stored the score in the db, ALL of search_mods' logic could be moved db-side
<HebaruSan[m]> And probably become lightning fast
<HebaruSan[m]> But thanks, that means that it does do the caching but the db objects are thunks
<HebaruSan[m]> OK, PR closed. And I pushed a change to my branch that MIGHT help with the default_version thing, when you have a chance.
RockyTV[m] has joined #spacedock
<RockyTV[m]> you can import the current app with `from flask import current_app`
<RockyTV[m]> sorry I have to catch up, watching a live stream of a colleague coding a new react component 😛
<RockyTV[m]> if you need decorators you shouldn't need to import app
DasSkelett[m] has quit [Quit: Idle timeout reached: 10800s]
HebaruSan[m] has quit [Quit: Idle timeout reached: 10800s]
RockyTV[m] has quit [Quit: Idle timeout reached: 10800s]
HebaruSan[m] has joined #spacedock
<HebaruSan[m]> But those are all well less than a second no?
<HebaruSan[m]> Other than your profile
<HebaruSan[m]> 🎉
im52kde has joined #spacedock
<HebaruSan[m]> Caching can be worthwhile, but it's no substitute for a good implementation of the thing being cached
godarklight[m] has joined #spacedock
<HebaruSan[m]> Same, flask_caching was kind of interesting
godarklight[m] has quit [Network ban]
im52kde has quit [Network ban]
HebaruSan[m] has quit [Network ban]
VITAS[m] has joined #spacedock
<VITAS[m]> during updates?
<VITAS[m]> when we update prod?
<VITAS[m]> no
<VITAS[m]> in general yes
<VITAS[m]> piwik /matomo
<VITAS[m]> i also have what ATS comes with
<VITAS[m]> a form of top and some api
<VITAS[m]> i remember you had acc to that?
<VITAS[m]> i cant
<VITAS[m]> youre in hell and not on matrix :>
<VITAS[m]> but wait you can come here
<VITAS[m]> juhu!
<VITAS[m]> sec
<VITAS[m]> i think the site was fast enough in the first place. i wont stop you from making it faster and improving the code :)
godarklight[m] has joined #spacedock
<godarklight[m]> I'm on matrix
pun[m] has joined #spacedock
godarklight[m] has quit [Network ban]
pun[m] has quit [Network ban]
VITAS[m] has quit [Network ban]
DasSkelett has joined #spacedock
HebaruSan has joined #spacedock
VITAS has joined #spacedock
djerun has joined #spacedock
godarklight[m] has joined #spacedock
im52kde has joined #spacedock
DasSkelett has quit [Network ban]
HebaruSan has quit [Network ban]
djerun has quit [Network ban]
godarklight[m] has quit [Network ban]
VITAS has quit [Network ban]
im52kde has quit [Network ban]
HebaruSan has joined #spacedock
DasSkelett has joined #spacedock
VITAS has joined #spacedock
djerun has joined #spacedock
godarklight[m] has joined #spacedock
im52kde has joined #spacedock
DasSkelett has quit [Network ban]
DasSkelett has joined #spacedock
pun[m] has joined #spacedock
Darklight[m] has joined #spacedock
HebaruSan[m] has joined #spacedock
<HebaruSan[m]> Meaning what exactly? The list of games?
<HebaruSan[m]> That's what comes up for `/`
<HebaruSan[m]> So this?
<HebaruSan[m]> I don't think there's anything slow there, it's a db query of 1 record
<HebaruSan[m]> https://spacedock.info/kerbal-space-program I could get on board with
<HebaruSan[m]> Huh, I get this. I wonder what part of my browser history it's using to decide that.
<HebaruSan[m]> Meanwhile I think I have to subscribe to that Youtube channel, he talks about all kinds of sci fi spacechips 🤤
<HebaruSan[m]> *edit:* ~~Meanwhile I think I have to subscribe to that Youtube channel, he talks about all kinds of sci fi spacechips 🤤~~ -> Meanwhile I think I have to subscribe to that Youtube channel, he talks about all kinds of sci fi spaceships 🤤
<HebaruSan[m]> <span class="d-mention d-user">RockyTV</span> There's a "restore branch" button on GitHub that I think any team member could use if that eventuality came about
<HebaruSan[m]> In the meantime I don't want to overrepresent how prodution-ready that change is
<HebaruSan[m]> Actually maybe the "restore branch" button only appears for me since I pushed it to my remote. Do you see it?
<HebaruSan[m]> OK, in case it is needed in the future, I pushed it here as well:
<HebaruSan[m]> 🐍
<HebaruSan[m]> You mean lambdas?
<HebaruSan[m]> If so, yes, but they're syntactically awkward
<HebaruSan[m]> `cache` is the first argument
<HebaruSan[m]> C# may be the best language, forgive my bias
<HebaruSan[m]> I would like to be loyal to C++, but there is just too much craziness there
<HebaruSan[m]> And also the need to consider whether you're dealing with the stack or the heap all the g-d time
<HebaruSan[m]> C# loses something with that limitation but the benefits are positively gigantic
<HebaruSan[m]> 😦 my main comment on that will pretty much be, let's use the module that's made for this
<Darklight[m]> Awake, going to write something to automate the tests first so I can get nice clean numbers and we can compare lots of different versions
<Darklight[m]> As things progress 🙂
<Darklight[m]> Skellets results (d95b3e0)
<Darklight[m]> ```
<Darklight[m]> skellet/_api_browse 50%: 149.890
<Darklight[m]> skellet/_api_browse_new 50%: 102.537
<Darklight[m]> skellet/_api_browse_top 50%: 89.587
<Darklight[m]> skellet/_api_browse_featured 50%: 3.333
<Darklight[m]> skellet/_api_mod_5 50%: 6.099
<Darklight[m]> skellet/_api_mod_5_5 50%: 3.989
RockyTV[m] has joined #spacedock
<Darklight[m]> skellet/_api_user_godarklight 50%: 4879.278
<Darklight[m]> skellet/_ 50%: 21.544
<RockyTV[m]> <span class="d-mention d-user">HebaruSan</span> you could reopen your PR and just setup flask-caching so it's there if we need to use it
<Darklight[m]> skellet/_ksp 50%: 118.552
<Darklight[m]> skellet/_browse 50%: 104.490
<Darklight[m]> skellet/_browse_new 50%: 145.408
<Darklight[m]> skellet/_browse_new.rss 50%: 11.638
<Darklight[m]> skellet/_browse_updated 50%: 151.747
<Darklight[m]> skellet/_browse_updated.rss 50%: 16.746
<Darklight[m]> skellet/_browse_top 50%: 169.788
<Darklight[m]> skellet/_browse_top.rss 50%: 16.478
<Darklight[m]> skellet/_browse_featured 50%: 22.137
<Darklight[m]> skellet/_browse_featured.rss 50%: 5.759
<Darklight[m]> skellet/_browse_all 50%: 167.779
<Darklight[m]> skellet/_ksp_browse 50%: 104.798
<Darklight[m]> skellet/_ksp_browse_new 50%: 147.224
<Darklight[m]> skellet/_ksp_browse_new.rss 50%: 13.035
<Darklight[m]> skellet/_ksp_browse_updated 50%: 153.411
<Darklight[m]> skellet/_ksp_browse_updated.rss 50%: 18.090
<Darklight[m]> skellet/_ksp_browse_top 50%: 169.066
<Darklight[m]> skellet/_ksp_browse_top.rss 50%: 16.453
<Darklight[m]> skellet/_ksp_browse_featured 50%: 24.654
<Darklight[m]> skellet/_ksp_browse_featured.rss 50%: 7.513
<Darklight[m]> skellet/_ksp_browse_all 50%: 169.175```
<Darklight[m]> I'll show alpha in a sec too
<Darklight[m]> The only standout is api/user/godarklight, but this is not a real issue at *people don't create 10000 mods*
<Darklight[m]> These are milliseconds
<Darklight[m]> Give me a bit for alpha to finish benching
<Darklight[m]> man I'm only doing 5 benchs a test because I know my endpoints take 20 seconds >.<
<Darklight[m]> This is taking a while bahahaha
<Darklight[m]> Point proven anyway, skellets approach is way better than the nonsense I did yesterday
<Darklight[m]> Cachcing is a spook 😛
<Darklight[m]> It was at least slightly worth barking up that tree though, I had completely forgot how spacedock worked and this kinda refreshed me in some areas
<Darklight[m]> Current alpha results, (0822bcd)
<Darklight[m]> ```0822bcd/_api_browse 50%: 65.322
<Darklight[m]> 0822bcd/_api_browse_new 50%: 109.582
<Darklight[m]> 0822bcd/_ksp_browse_featured 50%: 24.796
<Darklight[m]> 0822bcd/_ksp_browse_featured.rss 50%: 7.616
<Darklight[m]> 0822bcd/_ksp_browse_all 50%: 17439.365```
<Darklight[m]> It maaaay still be worth caching the main ksp page, 100ms response means it chokes at 10 requests a second, but that is where vitas threw heaps of instances at it to get it to work, I suspect a single gunicorn worker will handle this just fine given that it is literally 200 times faster
<Darklight[m]> Oh wait up
<Darklight[m]> That's only in some areas, the main page still takes the same time to load because it never went down the get_mods path
<Darklight[m]> I wonder if it is worth chucking the cache only on the main page, I think we need vitas to log into piwik and tell us how badly the main page is hit
<Darklight[m]> When you type spacedock into google what page you get
<Darklight[m]> Probably both / and /gameshort
<Darklight[m]> / is 20ms which I think is acceptable
<Darklight[m]> but /gameshort is 100
<Darklight[m]> Yeah
<Darklight[m]> And the gameshort version actually appears just above in the google search in my case
<Darklight[m]> Yeah google does that 😛
<Darklight[m]> But in either case they are right next to each other and people may see the KSP -spacedock an click that instead
<Darklight[m]> Given that I had a fight with flask-cache I'll temporarily mock it up the same way again but for that single endpoint, then if vitas comes back with numbers that suggest we should cache it then it'll be worth it
<Darklight[m]> I'll do it a bit neater than what I did previously too
<Darklight[m]> Aka it's going in its own file
<Darklight[m]> Oooohkay python is kinda weird
<Darklight[m]> Does python do anonymous functions in a sane way?
<Darklight[m]> File "/var/www/virtual/spacedock.info/htdocs/SpaceDock/KerbalStuff/blueprints/anonymous.py", line 28, in game
<Darklight[m]> ga = cache.get_key(gameshort + "_ga", ga_func)
<Darklight[m]> TypeError: get_key() takes 2 positional arguments but 3 were given
<Darklight[m]> Yeah, in what universe is this 3 arguments
<Darklight[m]> OH
<Darklight[m]> I forgot this
<Darklight[m]> I am a donkey
<Darklight[m]> I am so used to c# where we specify static or instance >><
<Darklight[m]> I am so used to c# where we specify static or instance >.<
<Darklight[m]> I'm with you there 😛
<Darklight[m]> Undefined Behaviour
<Darklight[m]> Making my own spacedock fork so I don't pollute the main repo with trash... I got *a* solution but not sure about it, it takes the load time from 100ms to 1ms though
<Darklight[m]> ```Percentage of the requests served within a certain time (ms)
<Darklight[m]> 50% 2
<Darklight[m]> 66% 2
<Darklight[m]> 75% 2
<Darklight[m]> 80% 2
<Darklight[m]> 90% 3
<Darklight[m]> 95% 4
<Darklight[m]> 98% 7
<Darklight[m]> 99% 11
<Darklight[m]> 100% 1231 (longest request)```
<Darklight[m]> Not sure what that little hickup was, could have been some vm weirdness, also this is 10000 requests with 10 concurrent requests going at all time
<Darklight[m]> Not sure what that little hickup was, could have been some vm weirdness, also this is 10000 requests with 10 concurrent requests going at all times
<Darklight[m]> On a single gunicorn instance
<Darklight[m]> If I bench it like I benched the others, this is 100 requests 1 request at a time ```Percentage of the requests served within a certain time (ms)
<Darklight[m]> 50% 1
<Darklight[m]> 66% 2
<Darklight[m]> 75% 2
<Darklight[m]> Odd... prod spacedock actually has a longer response time than my vm, 300ms (3req/s)
<Darklight[m]> So that's a potential bigger increase
<Darklight[m]> I am pretty sure alpha and prod have the same behaviour on that route atm. I think I'll leave it be for now, but it's there if you want it
<Darklight[m]> Or in general
<Darklight[m]> I'm just curious if it's even worth caching /kerbal-space-program, it takes 300ms and caching it inside of gunicorn can get it down to like 1
<Darklight[m]> Any really heavily hit pages would be worth doing
<Darklight[m]> If I still have the password, let me check 😛
<Darklight[m]> Looks like I got rid of the details a long time ago >.<
<Darklight[m]> At least now I am using a password manager so can keep them, you can dm me on matrix if you have spare time, but really I'm only curious in where the bulk of the hits go to.
<Darklight[m]> Eg if everyone directly goes to the mod page then who cares about the making the main one faster type of thing
<Darklight[m]> It took me a while to work it out, but yeah I think it's worth adding /game-short, / isn't justified as it's already pretty fast anyway
<Darklight[m]> It took me a while to work it out, but yeah I think it's worth adding /game-short, / isn't justified as it's already pretty fast anyway
<Darklight[m]> I feel like this should have been done back in the SirCmpwn days rather than bitching to majiir about not having powerful enough hardware 😛
<Darklight[m]> In that case spacedock might not have existed 😄
<Darklight[m]> I dug into https://github.com/sh4nks/flask-caching/tree/master/flask_caching and it seems like they are doing the exact same approach I am anyway, so that makes me more confident in my solution
<Darklight[m]> *edit:* ~~I dug into https://github.com/sh4nks/flask-caching/tree/master/flask_caching and it seems like they are doing the exact same approach I am anyway, so that makes me more confident in my solution~~ -> I dug into <https://github.com/sh4nks/flask-caching/tree/master/flask_caching> and it seems like they are doing the exact same approach I am anyway, so that makes me more confident in my solution
<Darklight[m]> Yeah, they were always a bit of a hothead, which isn't exactly a great attribute to have...
<Darklight[m]> Although I'm sure it's possible to optimise things to the point where it could run on a potato
<Darklight[m]> Time/efford reward tradeoff though
<Darklight[m]> *edit:* ~~Time/efford reward tradeoff though~~ -> Time/effort reward tradeoff though