Re: 2D map application: performance and design question
Excellent advice! With this I'm down to less than 0.02 secs for the 13x13 map rendering! Regards, Lars On Nov 2, 9:45 pm, Knut Ivar Nesheim wrote: > I would suggest rewriting the loop in your template as a templatetag. > Something like this > > @register.simple_tag > def render_locations(locations): > html = u""" html %(x)s stuff %(y)s here %(link)s """ > return '\n'.join([html % { 'x': loc.x, 'y': loc.y', 'link': > loc.link } for loc in locations]) > > I've used this approach a few times with good results for my use cases. > > Regards > Knut > > On Tue, Nov 2, 2010 at 9:28 PM, Lars Ruoff wrote: > > Ok, thanks for the suggestion, Javier. > > I implemented this and it showed: > > I'm spending about > > 0.2 secs for the queries, > > but 1.5 secs for t.render(c) ! > > > So rendering the template seems to take a significant amount of time! > > As you can see, my template code iterates over about 13*13=169 objects > > that have been passed in the context. > > I then made tests to reduce this number. Here is the result of time > > spent for the query and render() as a function of the grid size: > > 3*3: 0.03s, 0.1s > > 5*5: 0.04s, 0.25s > > 7*7: 0.08s, 0.45s > > 9*9: 0.13s, 0.72s > > 11*11: 0.17s, 1.1s > > 13*13: 0.2s, 1.5s > > > Lars > > > On Nov 2, 4:46 pm, Javier Guerra Giraldez wrote: > >> On Tue, Nov 2, 2010 at 3:35 AM, Lars Ruoff wrote: > >> > Ok, so having excluded SQLite and the static served files, I'd like to > >> > test if the server matters. What would be a minimum Apache install and > >> > config to run Django locally (on Windows)? > > >> again, that's _very_ unlikely to be the cause. why not profile a > >> little? if you're not handy with a python profiler, just set a var > >> 'starttime = datetime.now()' at the beginning of your view function > >> and a few 'print(datetime.now() - starttime)' at strategic points. > > >> -- > >> Javier > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com. > > For more options, visit this group > > athttp://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: 2D map application: performance and design question
I would suggest rewriting the loop in your template as a templatetag. Something like this @register.simple_tag def render_locations(locations): html = u""" html %(x)s stuff %(y)s here %(link)s """ return '\n'.join([html % { 'x': loc.x, 'y': loc.y', 'link': loc.link } for loc in locations]) I've used this approach a few times with good results for my use cases. Regards Knut On Tue, Nov 2, 2010 at 9:28 PM, Lars Ruoff wrote: > Ok, thanks for the suggestion, Javier. > I implemented this and it showed: > I'm spending about > 0.2 secs for the queries, > but 1.5 secs for t.render(c) ! > > So rendering the template seems to take a significant amount of time! > As you can see, my template code iterates over about 13*13=169 objects > that have been passed in the context. > I then made tests to reduce this number. Here is the result of time > spent for the query and render() as a function of the grid size: > 3*3: 0.03s, 0.1s > 5*5: 0.04s, 0.25s > 7*7: 0.08s, 0.45s > 9*9: 0.13s, 0.72s > 11*11: 0.17s, 1.1s > 13*13: 0.2s, 1.5s > > Lars > > > On Nov 2, 4:46 pm, Javier Guerra Giraldez wrote: >> On Tue, Nov 2, 2010 at 3:35 AM, Lars Ruoff wrote: >> > Ok, so having excluded SQLite and the static served files, I'd like to >> > test if the server matters. What would be a minimum Apache install and >> > config to run Django locally (on Windows)? >> >> again, that's _very_ unlikely to be the cause. why not profile a >> little? if you're not handy with a python profiler, just set a var >> 'starttime = datetime.now()' at the beginning of your view function >> and a few 'print(datetime.now() - starttime)' at strategic points. >> >> -- >> Javier > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: 2D map application: performance and design question
Ok, thanks for the suggestion, Javier. I implemented this and it showed: I'm spending about 0.2 secs for the queries, but 1.5 secs for t.render(c) ! So rendering the template seems to take a significant amount of time! As you can see, my template code iterates over about 13*13=169 objects that have been passed in the context. I then made tests to reduce this number. Here is the result of time spent for the query and render() as a function of the grid size: 3*3: 0.03s, 0.1s 5*5: 0.04s, 0.25s 7*7: 0.08s, 0.45s 9*9: 0.13s, 0.72s 11*11: 0.17s, 1.1s 13*13: 0.2s, 1.5s Lars On Nov 2, 4:46 pm, Javier Guerra Giraldez wrote: > On Tue, Nov 2, 2010 at 3:35 AM, Lars Ruoff wrote: > > Ok, so having excluded SQLite and the static served files, I'd like to > > test if the server matters. What would be a minimum Apache install and > > config to run Django locally (on Windows)? > > again, that's _very_ unlikely to be the cause. why not profile a > little? if you're not handy with a python profiler, just set a var > 'starttime = datetime.now()' at the beginning of your view function > and a few 'print(datetime.now() - starttime)' at strategic points. > > -- > Javier -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: 2D map application: performance and design question
On Tue, Nov 2, 2010 at 3:35 AM, Lars Ruoff wrote: > Ok, so having excluded SQLite and the static served files, I'd like to > test if the server matters. What would be a minimum Apache install and > config to run Django locally (on Windows)? again, that's _very_ unlikely to be the cause. why not profile a little? if you're not handy with a python profiler, just set a var 'starttime = datetime.now()' at the beginning of your view function and a few 'print(datetime.now() - starttime)' at strategic points. -- Javier -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: 2D map application: performance and design question
On Tue, 2010-11-02 at 01:35 -0700, Lars Ruoff wrote: > Ok, so having excluded SQLite and the static served files, I'd like to > test if the server matters. What would be a minimum Apache install and > config to run Django locally (on Windows)? try nginx+fcgi/tornado/your favourite webserver -- regards Kenneth Gonsalves Senior Associate NRC-FOSS at AU-KBC -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: 2D map application: performance and design question
Ok, so having excluded SQLite and the static served files, I'd like to test if the server matters. What would be a minimum Apache install and config to run Django locally (on Windows)? On Nov 1, 7:30 pm, Lars Ruoff wrote: > Ok, thanks all, > > So following Bill's advice, i did:>python manage.py shell > >>> import game.models > >>> list(game.models.Location.objects.filter( \ > > ... x__gte=34, \ > ... x__lte=46, \ > ... y__gte=24, \ > ... y__lte=36)) > > ...and the result showed up instantly! > So it seems DB is not the issue. > Will do other testing... > > On Nov 1, 4:18 pm, Bill Freeman wrote: > > > My experience with Django debug toolbar is that it makes things > > slow all by itself. > > > I have done a couple of apps that use the equivalent query, using > > PostgreSQL, > > without noticing a performance issue, with everything running on a Linux > > server. > > > 1. Have you tried timing the query by hand? That is, run the manage.py > > shell, > > import your model, and type a sample version of the query, wrapped in a > > list() > > operation to force the query to evaluate right away. If it's slow, > > then you problem > > is at least mostly in your DB/query choice. > > > 2. Is the machine in question tight on memory? That could make things > > slower > > that it would be on a production instance. > > > 3. You might look at the "range" field lookup instead of pairs of > > gte, lte. I doubt > > that it makes a performance difference, and I don't know if SQLite supports > > BETWEEN, but it's easy to try. > > > 4. You show x and y as integers, but if that was just by way of example, and > > they are really some complex (non-scalar) data type, the comparisons may not > > be cheap on the database. > > > Bill > > > On Mon, Nov 1, 2010 at 8:13 AM, Javier Guerra Giraldez > > > wrote: > > > On Mon, Nov 1, 2010 at 5:55 AM, Cal Leeming [Simplicity Media Ltd] > > > wrote: > > >> 9 out of 10 times, the bottleneck is usually the database > > > > true, but 8.7 of those 9 are about how the database is used, and not > > > about the engine choice. simply changing SQLite won't improve > > > significantly the one-user case. > > > > the trick is: 1) get as few db queries as possible for each page. 2) > > > use appropriate indices for those queries > > > > but first of all, you have to identify if it is really the DB where > > > you're spending time. the easiest way to be sure is to install > > > django_debug_toolbar app, it's great to tell you exactly what's going > > > on with the time and the DB accesses. > > > > -- > > > Javier > > > > -- > > > You received this message because you are subscribed to the Google Groups > > > "Django users" group. > > > To post to this group, send email to django-us...@googlegroups.com. > > > To unsubscribe from this group, send email to > > > django-users+unsubscr...@googlegroups.com. > > > For more options, visit this group > > > athttp://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: 2D map application: performance and design question
Ok, thanks all, So following Bill's advice, i did: >python manage.py shell >>> import game.models >>> list(game.models.Location.objects.filter( \ ... x__gte=34, \ ... x__lte=46, \ ... y__gte=24, \ ... y__lte=36)) ...and the result showed up instantly! So it seems DB is not the issue. Will do other testing... On Nov 1, 4:18 pm, Bill Freeman wrote: > My experience with Django debug toolbar is that it makes things > slow all by itself. > > I have done a couple of apps that use the equivalent query, using PostgreSQL, > without noticing a performance issue, with everything running on a Linux > server. > > 1. Have you tried timing the query by hand? That is, run the manage.py shell, > import your model, and type a sample version of the query, wrapped in a list() > operation to force the query to evaluate right away. If it's slow, > then you problem > is at least mostly in your DB/query choice. > > 2. Is the machine in question tight on memory? That could make things slower > that it would be on a production instance. > > 3. You might look at the "range" field lookup instead of pairs of > gte, lte. I doubt > that it makes a performance difference, and I don't know if SQLite supports > BETWEEN, but it's easy to try. > > 4. You show x and y as integers, but if that was just by way of example, and > they are really some complex (non-scalar) data type, the comparisons may not > be cheap on the database. > > Bill > > On Mon, Nov 1, 2010 at 8:13 AM, Javier Guerra Giraldez > > wrote: > > On Mon, Nov 1, 2010 at 5:55 AM, Cal Leeming [Simplicity Media Ltd] > > wrote: > >> 9 out of 10 times, the bottleneck is usually the database > > > true, but 8.7 of those 9 are about how the database is used, and not > > about the engine choice. simply changing SQLite won't improve > > significantly the one-user case. > > > the trick is: 1) get as few db queries as possible for each page. 2) > > use appropriate indices for those queries > > > but first of all, you have to identify if it is really the DB where > > you're spending time. the easiest way to be sure is to install > > django_debug_toolbar app, it's great to tell you exactly what's going > > on with the time and the DB accesses. > > > -- > > Javier > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com. > > For more options, visit this group > > athttp://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: 2D map application: performance and design question
My experience with Django debug toolbar is that it makes things slow all by itself. I have done a couple of apps that use the equivalent query, using PostgreSQL, without noticing a performance issue, with everything running on a Linux server. 1. Have you tried timing the query by hand? That is, run the manage.py shell, import your model, and type a sample version of the query, wrapped in a list() operation to force the query to evaluate right away. If it's slow, then you problem is at least mostly in your DB/query choice. 2. Is the machine in question tight on memory? That could make things slower that it would be on a production instance. 3. You might look at the "range" field lookup instead of pairs of gte, lte. I doubt that it makes a performance difference, and I don't know if SQLite supports BETWEEN, but it's easy to try. 4. You show x and y as integers, but if that was just by way of example, and they are really some complex (non-scalar) data type, the comparisons may not be cheap on the database. Bill On Mon, Nov 1, 2010 at 8:13 AM, Javier Guerra Giraldez wrote: > On Mon, Nov 1, 2010 at 5:55 AM, Cal Leeming [Simplicity Media Ltd] > wrote: >> 9 out of 10 times, the bottleneck is usually the database > > true, but 8.7 of those 9 are about how the database is used, and not > about the engine choice. simply changing SQLite won't improve > significantly the one-user case. > > the trick is: 1) get as few db queries as possible for each page. 2) > use appropriate indices for those queries > > but first of all, you have to identify if it is really the DB where > you're spending time. the easiest way to be sure is to install > django_debug_toolbar app, it's great to tell you exactly what's going > on with the time and the DB accesses. > > -- > Javier > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: 2D map application: performance and design question
On Mon, Nov 1, 2010 at 5:55 AM, Cal Leeming [Simplicity Media Ltd] wrote: > 9 out of 10 times, the bottleneck is usually the database true, but 8.7 of those 9 are about how the database is used, and not about the engine choice. simply changing SQLite won't improve significantly the one-user case. the trick is: 1) get as few db queries as possible for each page. 2) use appropriate indices for those queries but first of all, you have to identify if it is really the DB where you're spending time. the easiest way to be sure is to install django_debug_toolbar app, it's great to tell you exactly what's going on with the time and the DB accesses. -- Javier -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: 2D map application: performance and design question
Hi Lukasz, see my answer to Daniel. Replacing images by text didn't speed up things much. Is there any other test/profiling that i should do? Would taking the systime before and after the query give me some hints? I'll try this later... On Nov 1, 12:39 pm, Łukasz Rekucki wrote: > On 1 November 2010 10:59, Lars Ruoff wrote: > > > > > Hello, > > > first of all, these are my first steps with Django, and i only have > > limited experience with Python, so please be patient. > > > I'm using it for what is intended to be a browser game in the future. > > The main part of the game is a zoom view on a two-dimensional map of > > fields. > > > I'm currently using Django 1.2.3 with Python 2.6 on Windows XP. > > I'm using Python-provided SQLite and Django's local debug HTTP server > > during development ('python manage.py runserver'). > > > It works pretty well, but i notice that it takes several seconds to > > update the map screen, which i consider unacceptable given the fact > > that it runs locally. > > > I'm wondering where the performance bottleneck lies here. > > Is it... > > - SQLLite? (I.e. would switching to say PostgreSQL speed things up > > considerably?) > > It could actually slow down things. Independently of the DB, you want > to set up some indexes on your models (but I don't think that's your > problem atm). > > > - Djangos debug web server? (I.e. would switching to apache speed > > things up considerably?) > > Bingo! The development server is single-threaded and slow, so it > totally sucks at serving *static files*. Looking at your template, > your map is composed of many images and they all have to load > sequentially via the devserver. Serving those images using Apache or > Nginx should speed up things significantly. > > > - or the way my application is designed?? > > In the long term, when the DB really starts to be your bottleneck, you > want to do some research about all things "spatial" (like spatial > indexes). > > -- > Łukasz Rekucki -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: 2D map application: performance and design question
On 1 November 2010 10:59, Lars Ruoff wrote: > Hello, > > first of all, these are my first steps with Django, and i only have > limited experience with Python, so please be patient. > > I'm using it for what is intended to be a browser game in the future. > The main part of the game is a zoom view on a two-dimensional map of > fields. > > I'm currently using Django 1.2.3 with Python 2.6 on Windows XP. > I'm using Python-provided SQLite and Django's local debug HTTP server > during development ('python manage.py runserver'). > > It works pretty well, but i notice that it takes several seconds to > update the map screen, which i consider unacceptable given the fact > that it runs locally. > > I'm wondering where the performance bottleneck lies here. > Is it... > - SQLLite? (I.e. would switching to say PostgreSQL speed things up > considerably?) It could actually slow down things. Independently of the DB, you want to set up some indexes on your models (but I don't think that's your problem atm). > - Djangos debug web server? (I.e. would switching to apache speed > things up considerably?) Bingo! The development server is single-threaded and slow, so it totally sucks at serving *static files*. Looking at your template, your map is composed of many images and they all have to load sequentially via the devserver. Serving those images using Apache or Nginx should speed up things significantly. > - or the way my application is designed?? In the long term, when the DB really starts to be your bottleneck, you want to do some research about all things "spatial" (like spatial indexes). -- Łukasz Rekucki -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: 2D map application: performance and design question
Hi Daniel, you are right that images are being loaded. But i gave it a try and replaced the images by text. Still the page takes about 3 seconds to load. Lars On Nov 1, 12:30 pm, Daniel Roseman wrote: > It's a bit hard to tell without knowing how the slowness appears. What > exactly is slow? > > My instinct would be that it's simply a matter of image loading. Don't > forget that the development server can only serve one thing at a time, > so if you're loading a lot of images they are going to come up slowly. > A dedicated server will be a lot better for that - might be worth > experimenting with setting up Apache or Nginx or Lightppd just to > serve the images for now, to see if that helps. > -- > DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: 2D map application: performance and design question
Ok, but that said, the database isn't that big here. (Well, i guess) There are currently 4800 entries in the "Location" table. Is this too much for SQLite already? May it be the query in locations = Location.objects.filter( \ x__gte=center_location.x-half_x, \ x__lte=center_location.x+half_x, \ y__gte=center_location.y-half_y, \ y__lte=center_location.y+half_y) that might be non-optimal? How to improve it? Lars On Nov 1, 11:55 am, "Cal Leeming [Simplicity Media Ltd]" wrote: > Hi Lars, > > Unless you are doing some *really* intense Python code in your business > logic, then 9 out of 10 times, the bottleneck is usually the database, > especially if you are using Python. > > Cal -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: 2D map application: performance and design question
On Nov 1, 9:59 am, Lars Ruoff wrote: > Hello, > > first of all, these are my first steps with Django, and i only have > limited experience with Python, so please be patient. > > I'm using it for what is intended to be a browser game in the future. > The main part of the game is a zoom view on a two-dimensional map of > fields. > > I'm currently using Django 1.2.3 with Python 2.6 on Windows XP. > I'm using Python-provided SQLite and Django's local debug HTTP server > during development ('python manage.py runserver'). > > It works pretty well, but i notice that it takes several seconds to > update the map screen, which i consider unacceptable given the fact > that it runs locally. > > I'm wondering where the performance bottleneck lies here. > Is it... > - SQLLite? (I.e. would switching to say PostgreSQL speed things up > considerably?) > - Djangos debug web server? (I.e. would switching to apache speed > things up considerably?) > - or the way my application is designed?? > > Since the latter is a very probable answer, here is the way it works > in a nutshell: > > The model is something like: > > class Terrain(models.Model): > image_file = models.CharField(max_length=80) > > class Location(models.Model): > x = models.IntegerField() > y = models.IntegerField() > terrain = models.ForeignKey(Terrain) > > The heart of the view goes like this: > > center_location = Location.objects.get(id=location_id) > > ## how many fields on the map view in each direction > half_x = 6 > half_y = 6 > > locations = Location.objects.filter( \ > x__gte=center_location.x-half_x, \ > x__lte=center_location.x+half_x, \ > y__gte=center_location.y-half_y, \ > y__lte=center_location.y+half_y) > > locs = [] > for l in locations: > loc_info = {'id': l.id, \ > 'x': l.x - center_location.x + half_x, \ > 'y': l.y - center_location.y + half_y, \ > 'img': l.terrain.image_file} > locs.append(loc_info) > > c = Context({ > 'locs': locs, > }) > return HttpResponse(t.render(c)) > > And the main part of the template renders these items: > > {% for l in locs %} > src="/images/{{l.img}}" /> > {% endfor %} > > Do you see any issues with this approach? Any paths to performance > improvements? > Since i'm at the beginning of this project i would like to avoid going > the wrong way. > > best regards, > Lars It's a bit hard to tell without knowing how the slowness appears. What exactly is slow? My instinct would be that it's simply a matter of image loading. Don't forget that the development server can only serve one thing at a time, so if you're loading a lot of images they are going to come up slowly. A dedicated server will be a lot better for that - might be worth experimenting with setting up Apache or Nginx or Lightppd just to serve the images for now, to see if that helps. -- DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: 2D map application: performance and design question
Hi Lars, Unless you are doing some *really* intense Python code in your business logic, then 9 out of 10 times, the bottleneck is usually the database, especially if you are using Python. Cal On Mon, Nov 1, 2010 at 9:59 AM, Lars Ruoff wrote: > Hello, > > first of all, these are my first steps with Django, and i only have > limited experience with Python, so please be patient. > > I'm using it for what is intended to be a browser game in the future. > The main part of the game is a zoom view on a two-dimensional map of > fields. > > I'm currently using Django 1.2.3 with Python 2.6 on Windows XP. > I'm using Python-provided SQLite and Django's local debug HTTP server > during development ('python manage.py runserver'). > > It works pretty well, but i notice that it takes several seconds to > update the map screen, which i consider unacceptable given the fact > that it runs locally. > > I'm wondering where the performance bottleneck lies here. > Is it... > - SQLLite? (I.e. would switching to say PostgreSQL speed things up > considerably?) > - Djangos debug web server? (I.e. would switching to apache speed > things up considerably?) > - or the way my application is designed?? > > Since the latter is a very probable answer, here is the way it works > in a nutshell: > > The model is something like: > > class Terrain(models.Model): >image_file = models.CharField(max_length=80) > > class Location(models.Model): >x = models.IntegerField() >y = models.IntegerField() >terrain = models.ForeignKey(Terrain) > > > The heart of the view goes like this: > >center_location = Location.objects.get(id=location_id) > >## how many fields on the map view in each direction >half_x = 6 >half_y = 6 > >locations = Location.objects.filter( \ >x__gte=center_location.x-half_x, \ >x__lte=center_location.x+half_x, \ >y__gte=center_location.y-half_y, \ >y__lte=center_location.y+half_y) > >locs = [] >for l in locations: >loc_info = {'id': l.id, \ >'x': l.x - center_location.x + half_x, \ >'y': l.y - center_location.y + half_y, \ >'img': l.terrain.image_file} >locs.append(loc_info) > >c = Context({ >'locs': locs, >}) >return HttpResponse(t.render(c)) > > > And the main part of the template renders these items: > > {% for l in locs %} > src="/images/{{l.img}}" /> > {% endfor %} > > > Do you see any issues with this approach? Any paths to performance > improvements? > Since i'm at the beginning of this project i would like to avoid going > the wrong way. > > best regards, > Lars > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- Cal Leeming Operational Security & Support Team *Out of Hours: *+44 (07534) 971120 | *Support Tickets: * supp...@simplicitymedialtd.co.uk *Fax: *+44 (02476) 578987 | *Email: *cal.leem...@simplicitymedialtd.co.uk *IM: *AIM / ICQ / MSN / Skype (available upon request) Simplicity Media Ltd. All rights reserved. Registered company number 7143564 -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.