Rich,

I believe you know a lot way more than me about AWS Lambda since you have 
made such a great project, and I'm really interested to know how it really 
works since theyr documentation is a bit superficial.

On their FAQ this is what they state:

*Q: Will AWS Lambda reuse function instances?*

To improve performance, AWS Lambda may choose to retain an instance of your 
function and reuse it to serve a subsequent request, rather than creating a 
new copy. Your code should not assume that this will always happen.


I always thought, and with very simple testing seen, that your code is 
basically "frozen" between each request, and for example, every import that 
is done in the main module is always done once (so your whole program is 
only initialized once) so this means django would only initialize once for 
quite a while (until your instance of the code is discarded, and a new 
request will basically generate all modules to be imported again). So 
technically if you do the right imports to have django call setup(), this 
should be only done once. What is really happening that makes it always 
call setup() on every request?


With the above said, if that's really the case. Python is known to able to 
serialize classes in a very interesting way (pickling) where you can even 
send a class with its methods over the wire and on the other side the 
person can execute every method defined in there and the class also keeps 
any state. Would it be possible to store the state with this somehow?





El viernes, 26 de febrero de 2016, 17:53:00 (UTC-3), Rich Jones escribió:
>
> @Aymeric
> > In my opinion, the first concrete step would be to measure how much time 
> is spent executing Django code rather than importing Python modules.
>
> You can find a complete profile of a Django request as it goes through the 
> complete request/response loop here: 
> https://github.com/Miserlou/django-zappa/files/141600/profile.txt
>
> Over 70% of the total request time is spent in django.setup() - so you can 
> see why we have an incentive to improve this! 
>
>
> @ Cristiano - 
> > If with "serverless" you are talking deployments such as Amazon Lambda 
> or similar, I don't think setup is called on every request, at least for 
> AWS Lambda, the enviorment is cached so it will only happen once each time 
> it needs to scale up. Are there any other issues?
>
> You're halfway there, but the process is more complicated than that. The 
> code is cached, not the internal state of the machine. You can follow our 
> progress here: https://github.com/Miserlou/django-zappa/
>
> But - another type caching could be another possibility. Can anybody think 
> of any arrangements where we could perhaps call setup() with 
> "pre-loaded"/cached applications? 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/5c84c0a5-0ecd-4c80-8560-919cdd7b0879%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to