[google-appengine] Re: What is a proper way to cache values on "per request" basis?

2008-12-01 Thread Joel Odom
Try getting rid of the memcache in favor of a hard-coded value (for testing
purposes only).  If you're still getting high CPU usage, then the problem is
not with your use of memcache.
You can also use global variables to cache values, as long as you're
careful.



On Mon, Dec 1, 2008 at 2:28 PM, Sharp-Developer.Net <
[EMAIL PROTECTED]> wrote:

>
> Hi,
>
> I have to retrieve some entities by key multiple times during single
> request.
>
> I do use memcache but getting quite high CPU usage and lot's of
> warnings.
>
> As I retrieve the same entity by it key multiple (many) times during a
> request I wonder could I improve my code by caching results on per
> request handler instance basis? I sure I could but as newbie in Python
> I'm not sure what is the best place & way to do that.
>
> I could add variable to a request object (I use Django) but that will
> require to pass it to every place where I need to use it. It's too
> complicated.
>
> I wonder is there such a thing like a HttpContext.Current in C#? In
> ASP.NET if I want to store/retrieve an object on per request basis
> I'll simply do next:
>
>   HttpContext.Current.Items["key"] = value;
>   var value = HttpContext.Current.Items["key"];
>
> Is the anything similar in AppEngine/Python?
>
> Again, as a Python newbie will apreciate a working code sample.
>
> I think this question could be interesting to many people.
> >
>


-- 
http://giscoder.blogspot.com/

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: What is a proper way to cache values on "per request" basis?

2008-12-01 Thread Sharp-Developer.Net

Ok, may be the problem was in json serialization/deserialization.

But I'm learning the Python/GAE and still eager to get answer to my
question regarding how to store some values accessible throug out
request without passing them through out all my layers.

Any help?
--
Alex
http://sharp-developer.net/

On Dec 1, 7:39 pm, "Joel Odom" <[EMAIL PROTECTED]> wrote:
> Try getting rid of the memcache in favor of a hard-coded value (for testing
> purposes only).  If you're still getting high CPU usage, then the problem is
> not with your use of memcache.
> You can also use global variables to cache values, as long as you're
> careful.
>
> On Mon, Dec 1, 2008 at 2:28 PM, Sharp-Developer.Net <
>
>
>
> [EMAIL PROTECTED]> wrote:
>
> > Hi,
>
> > I have to retrieve some entities by key multiple times during single
> > request.
>
> > I do use memcache but getting quite high CPU usage and lot's of
> > warnings.
>
> > As I retrieve the same entity by it key multiple (many) times during a
> > request I wonder could I improve my code by caching results on per
> > request handler instance basis? I sure I could but as newbie in Python
> > I'm not sure what is the best place & way to do that.
>
> > I could add variable to a request object (I use Django) but that will
> > require to pass it to every place where I need to use it. It's too
> > complicated.
>
> > I wonder is there such a thing like a HttpContext.Current in C#? In
> > ASP.NET if I want to store/retrieve an object on per request basis
> > I'll simply do next:
>
> >   HttpContext.Current.Items["key"] = value;
> >   var value = HttpContext.Current.Items["key"];
>
> > Is the anything similar in AppEngine/Python?
>
> > Again, as a Python newbie will apreciate a working code sample.
>
> > I think this question could be interesting to many people.
>
> --http://giscoder.blogspot.com/
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: What is a proper way to cache values on "per request" basis?

2008-12-01 Thread yejun

You can save it to a global variable as cache.
You can use a module level variable as cache and clear it in the
handler's __init__.

On Dec 1, 2:28 pm, "Sharp-Developer.Net"
<[EMAIL PROTECTED]> wrote:
> Hi,
>
> I have to retrieve some entities by key multiple times during single
> request.
>
> I do use memcache but getting quite high CPU usage and lot's of
> warnings.
>
> As I retrieve the same entity by it key multiple (many) times during a
> request I wonder could I improve my code by caching results on per
> request handler instance basis? I sure I could but as newbie in Python
> I'm not sure what is the best place & way to do that.
>
> I could add variable to a request object (I use Django) but that will
> require to pass it to every place where I need to use it. It's too
> complicated.
>
> I wonder is there such a thing like a HttpContext.Current in C#? In
> ASP.NET if I want to store/retrieve an object on per request basis
> I'll simply do next:
>
>    HttpContext.Current.Items["key"] = value;
>    var value = HttpContext.Current.Items["key"];
>
> Is the anything similar in AppEngine/Python?
>
> Again, as a Python newbie will apreciate a working code sample.
>
> I think this question could be interesting to many people.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: What is a proper way to cache values on "per request" basis?

2008-12-01 Thread yejun

For example,

import __main__

class yourhandler(webapp.RequestHandler):
def __init__():
__main__.cache = {}

On Dec 1, 9:00 pm, yejun <[EMAIL PROTECTED]> wrote:
> You can save it to a global variable as cache.
> You can use a module level variable as cache and clear it in the
> handler's __init__.
>
> On Dec 1, 2:28 pm, "Sharp-Developer.Net"
>
> <[EMAIL PROTECTED]> wrote:
> > Hi,
>
> > I have to retrieve some entities by key multiple times during single
> > request.
>
> > I do use memcache but getting quite high CPU usage and lot's of
> > warnings.
>
> > As I retrieve the same entity by it key multiple (many) times during a
> > request I wonder could I improve my code by caching results on per
> > request handler instance basis? I sure I could but as newbie in Python
> > I'm not sure what is the best place & way to do that.
>
> > I could add variable to a request object (I use Django) but that will
> > require to pass it to every place where I need to use it. It's too
> > complicated.
>
> > I wonder is there such a thing like a HttpContext.Current in C#? In
> > ASP.NET if I want to store/retrieve an object on per request basis
> > I'll simply do next:
>
> >    HttpContext.Current.Items["key"] = value;
> >    var value = HttpContext.Current.Items["key"];
>
> > Is the anything similar in AppEngine/Python?
>
> > Again, as a Python newbie will apreciate a working code sample.
>
> > I think this question could be interesting to many people.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: What is a proper way to cache values on "per request" basis?

2008-12-01 Thread Sharp-Developer.Net

Would not be that thread unsafe?

As I understand modules are loaded once per machine instance and then
cached/reused by different requests.

I'm not sure what is the "__main__" module. I don't have such.

So I afraid if I cache in module user specific information it will
become visible to another thread of my app running on the same box.
--
Alexander Trakhimenok
http://sharp-developer.net/

On Dec 2, 2:04 am, yejun <[EMAIL PROTECTED]> wrote:
> For example,
>
> import __main__
>
> class yourhandler(webapp.RequestHandler):
>     def __init__():
>         __main__.cache = {}
>
> On Dec 1, 9:00 pm, yejun <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > You can save it to a global variable as cache.
> > You can use a module level variable as cache and clear it in the
> > handler's __init__.
>
> > On Dec 1, 2:28 pm, "Sharp-Developer.Net"
>
> > <[EMAIL PROTECTED]> wrote:
> > > Hi,
>
> > > I have to retrieve some entities by key multiple times during single
> > > request.
>
> > > I do use memcache but getting quite high CPU usage and lot's of
> > > warnings.
>
> > > As I retrieve the same entity by it key multiple (many) times during a
> > > request I wonder could I improve my code by caching results on per
> > > request handler instance basis? I sure I could but as newbie in Python
> > > I'm not sure what is the best place & way to do that.
>
> > > I could add variable to a request object (I use Django) but that will
> > > require to pass it to every place where I need to use it. It's too
> > > complicated.
>
> > > I wonder is there such a thing like a HttpContext.Current in C#? In
> > > ASP.NET if I want to store/retrieve an object on per request basis
> > > I'll simply do next:
>
> > >    HttpContext.Current.Items["key"] = value;
> > >    var value = HttpContext.Current.Items["key"];
>
> > > Is the anything similar in AppEngine/Python?
>
> > > Again, as a Python newbie will apreciate a working code sample.
>
> > > I think this question could be interesting to many people.
>
>
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: What is a proper way to cache values on "per request" basis?

2008-12-02 Thread yejun

GAE is single thread server.

On Dec 2, 2:50 am, "Sharp-Developer.Net"
<[EMAIL PROTECTED]> wrote:
> Would not be that thread unsafe?
>
> As I understand modules are loaded once per machine instance and then
> cached/reused by different requests.
>
> I'm not sure what is the "__main__" module. I don't have such.
>
> So I afraid if I cache in module user specific information it will
> become visible to another thread of my app running on the same box.
> --
> Alexander Trakhimenokhttp://sharp-developer.net/
>
> On Dec 2, 2:04 am, yejun <[EMAIL PROTECTED]> wrote:
>
> > For example,
>
> > import __main__
>
> > class yourhandler(webapp.RequestHandler):
> >     def __init__():
> >         __main__.cache = {}
>
> > On Dec 1, 9:00 pm, yejun <[EMAIL PROTECTED]> wrote:
>
> > > You can save it to a global variable as cache.
> > > You can use a module level variable as cache and clear it in the
> > > handler's __init__.
>
> > > On Dec 1, 2:28 pm, "Sharp-Developer.Net"
>
> > > <[EMAIL PROTECTED]> wrote:
> > > > Hi,
>
> > > > I have to retrieve some entities by key multiple times during single
> > > > request.
>
> > > > I do use memcache but getting quite high CPU usage and lot's of
> > > > warnings.
>
> > > > As I retrieve the same entity by it key multiple (many) times during a
> > > > request I wonder could I improve my code by caching results on per
> > > > request handler instance basis? I sure I could but as newbie in Python
> > > > I'm not sure what is the best place & way to do that.
>
> > > > I could add variable to a request object (I use Django) but that will
> > > > require to pass it to every place where I need to use it. It's too
> > > > complicated.
>
> > > > I wonder is there such a thing like a HttpContext.Current in C#? In
> > > > ASP.NET if I want to store/retrieve an object on per request basis
> > > > I'll simply do next:
>
> > > >    HttpContext.Current.Items["key"] = value;
> > > >    var value = HttpContext.Current.Items["key"];
>
> > > > Is the anything similar in AppEngine/Python?
>
> > > > Again, as a Python newbie will apreciate a working code sample.
>
> > > > I think this question could be interesting to many people.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---