how to make django-template cache refresh initiatively
Sammichmaker has quit
FunkyBob
initiatively?
SimpleName
I don’t want to the first user access website feel slowly
sridar joined the channel
period refresh
reentec has quit
FunkyBob
one of these days you my actually persuade me you need caching
but every time I try to find out... you stop answering
uestra has quit
schinckel
You mean you want the cache warmed? Can you give some examples of the stuff that needs to be in the cache, and why it can't just be lazily done?
sridar
Can someone give me example link for the cascade select app ?
FunkyBob
schinckel: SimpleName needs to display 20 products on their front page
sridar: did you check djangopackages?
SimpleName
- - ! I am so sorry @funkybob
schinckel
Oh, this was the 100000 queries for 20 objects?
FunkyBob
schinckel: seems so
turns out it was 100000 products, and only showing 20 of
sridar
Hold on, let me check it again and confirm
FunkyBob
but more details we never got
mikea
sridar: it's called Smart Selects
FunkyBob
mikea: is it?
mikea: why did you look up SO, btw, when what you needed was in the docs I linked to?
sridar
I tried smart selects but cascading option is not working and I have reported this as issue with another user in their issue list
mikea
unless I misunderstood the question
FunkyBob, I was having a difficult time maping what you linked into annotations
sridar, did you setup their urls.py stuff?
sridar
yes I did
it works for the type of method that they mentioned as example
but not with my scenario
mikea
ah, k
FunkyBob, you got me 80% of the way there. It gave me the info I needed to search for the right answer on my own
FunkyBob
yeah, but SO. man.... don't encourage them
mikea
heh
sridar has quit
SimpleName
I need to caculate top 20 of 100000, by a hot algorithm
and the algorithm is complex
I know I can caculate the result every time , when score of every product update, but the truth, the project is not I write, I just update it,
Koterpillar
SimpleName: you have me 50% convinced that you need caching; if your algorithm needs to look at 100000 products, you still need to look into optimizing the algorithm
psachin joined the channel
TakinOver has quit
reentec joined the channel
SimpleName
of course, but there is a question that: the project is not I write it, now I just update it to make it faster
JohnnyZ_ has quit
Koterpillar
SimpleName: do you have celery?
SimpleName: or anything like that?
SimpleName
of course, I use celery to refresh cache period
: )
i use CELERYBEAT_SCHEDULE
Koterpillar
then just run the algorithm every 10 minutes and set is_on_home_page=True on those projects
*products
then filter the home page by is_on_home_page=True
no caching needed
Tipuch joined the channel
SimpleName
but not only query the result, and I need handle the result , for example, I need to get the field content of every queryset
generate a json data to client
Koterpillar
SimpleName: for only 20 objects, it will be fast
SimpleName
in fact, 1000 online user access it at same time
FunkyBob
SimpleName: my question remains -- what actual efforts have you done to optimise this calculation?
SimpleName
your method is good, but I think the result cached just only one minute, but it can reduce my server press
sridar joined the channel
Koterpillar
SimpleName: the standard django caching will not solve your problem _at least_ because the first user will have to wait
SimpleName
of course, so I have to use celery period task
to solve it
Koterpillar
so, what is - currently - the result of the task?
HTML markup? JSON?
FunkyBob
if you want to be smarter than caching... you can look at pre-emptive generation
Koterpillar
^^ this
FunkyBob
do you know what events will cause the data to become stale?
Koterpillar
"a second passed"
reentec has quit
(guessing)
mikea
I would do pre-emptive generation and stick it in something like redis or memcache
keimlink joined the channel
SimpleName
json
Koterpillar
SimpleName: so what are you loading on the front page?
SimpleName: in fact, _why_ is the front page slow?
mikea
you can use memcache or redis outside of the django caching framework if it's just that one piece of data that needs to be cached
SimpleName
not slow, only the first user slow
Koterpillar
SimpleName: for the first user, why is it slow?
FunkyBob
Koterpillar: this is what I've been trying to get out of SimpleName for the last week of two
SimpleName
of course, I use redis cache django template
Koterpillar
FunkyBob: I saw one iteration
SimpleName
- - !
FunkyBob
SimpleName: stop talking about the cache... start telling us about what needst to happen to generate the cache value
explain why _that_ is slow,
Koterpillar
SimpleName: imagine that you removed the cache tag
SimpleName: it's going to be slow for everyone now, but why?
schinckel
BECAUSE I'M NOT CACHING
FunkyBob
heh
SimpleName
no, just first user have to wait for it , just 3 second
other people is very fast
FunkyBob
SimpleName: you're not listening
mikea
What does the process do that takes 3 seconds?
FunkyBob
SimpleName: when calculating the value to put in the cache.... why does it take so long?
what work is it doing?
schinckel
Yeah. Pretend that there is no caching.
FunkyBob
what have you done to make it faster? what have you done to understand why it is slow?
SimpleName
because the old staff use a complex algorythm
FunkyBob
because caching is NOT a good solution
SimpleName
I can ’t use new way
FunkyBob
why not?
mikea
select * from table; for each result in results: i += 1
lol
SimpleName
- - !
schinckel
What is it about the old algorithm that makes it slow?
FunkyBob
what the fuck is this "- - ! " supposed to mean, SimpleName ?
schinckel
What is it about the problem that means you can't use a new algorithm?
SimpleName
_ - ! mean awkard
sridar has quit
FunkyBob
SimpleName: we're tryign to help you fix the problem... but every time we try, you stop us.
SimpleName
My company dont let me use new algorithm
Sammichmaker joined the channel
no
mikea
What I think he's saying is that he's not allowed to change the algorithm
SimpleName
yes
FunkyBob
so implement the algorithm better
SimpleName
of course, If I have chance, I will change it
FunkyBob
as I asked you every other time... how many DB queries does it make per Product?
it could be you could make this all a LOT faster by using prefetch_related and/or select_related
but you never answer my question... so ... we don't know
SimpleName
at least, there is 50, 000 to use the complex algorithm to generate the month top’s product
FunkyBob
SimpleName: PER PRODUCT
Koterpillar
SimpleName: your goal is NOT to run this algorithm in the template
jessamynsmith has quit
FunkyBob
SimpleName: to generate details for a SINGLE PRODUCT... _how_ many DB queries?
SimpleName
yes
FunkyBob
50,000 DB queries PER PRODUCT???
SimpleName
I just use 5 of 50, 000
mikea
lol
FunkyBob
use 5 what of 50,000?
garygraham2 has quit
schinckel
Do you understand the difference between a row and a query?
SimpleName
product
FunkyBob
SimpleName: no... I'm asking about a _single_ product