Hi,

Thanks for your response. But I have observed the following:

Without Iterator: It takes a bit of a time before the for loop is executed 
and also the CPU spikes up during that period and so does the Memory - 
which implies the DB is accessed to fetch all the results.

With iterator: The for loop execution starts immediately and the memory 
usage is also low. This probably implies that not all the results are 
fetched with a single query. 

Based on what you have mentioned, I am not sure how to understand the above 
behaviour. 

Thanks,

On Friday, March 17, 2017 at 11:27:52 AM UTC+5:30, Shawn Milochik wrote:
>
> I think the benefit of using the iterator is best explained by an example:
>
> Without iterator:
>
> You loop through the queryset, using each item for  whatever you're doing. 
> As you do this, all the items are now in your local scope, using up RAM. 
> If, after the loop, you should want to loop through the data again, you 
> can. Upside: Can re-use the data. Downside: memory usage.
>
> With iterator:
>
> You loop through the queryset, using each item for  whatever you're doing. 
> As you do this, read items are garbage-collected. If you want to loop 
> through the data again, you'll have to hit the database again. Upside: 
> Memory usage.
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/aa3da7de-a700-48fc-bf30-1c41d11b1d56%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to