Open mikehand opened 8 years ago
cc: @mrealm, @dadrian
It looks like a SQL query is so complex / accidentally recursive, that the query compilation process recursively calls itself enough that the program crashes. Do you run some sort of scheduled calendar update, or do you have some sort of infinite retry process if something go wrong?
ASSIGN #206 TO MY BUTT
On Sunday, February 7, 2016, David Adrian notifications@github.com wrote:
It looks like a SQL query is so complex / accidentally recursive, that the query compilation process recursively calls itself enough that the program crashes. Do you run some sort of scheduled calendar update, or do you have some sort of infinite retry process if something go wrong?
— Reply to this email directly or view it on GitHub https://github.com/tbpmig/mig-website/issues/206#issuecomment-180946909.
So it's not a scheduled thing (AFAICT) because the source of the error is from a view function...
I'm not sure about the retry process, is that a db config thing?
I mean, do you hit Google Calendar when you load this page?
No that's just the main cal page and event (un)sign up logic
On Sunday, February 7, 2016, David Adrian notifications@github.com wrote:
I mean, do you hit Google Calendar when you load this page?
— Reply to this email directly or view it on GitHub https://github.com/tbpmig/mig-website/issues/206#issuecomment-181056220.
Michael Hand Electrical Engineering/Control Systems M.S.E. The University of Michigan mikehand@umich.edu
Do you have any DB access/query logs?
Also, which file is this source in?
Source is in event_cal/views.py function name event_list, not sure that will be much help as the offending call is likely buried in django. Kyle would need to pull logs
Michael Hand Electrical Engineering/Control Systems M.S.E. The University of Michigan mikehand@umich.edu
On Mon, Feb 8, 2016 at 8:01 PM, David Adrian notifications@github.com wrote:
Also, which file is this source in?
— Reply to this email directly or view it on GitHub https://github.com/tbpmig/mig-website/issues/206#issuecomment-181650333.
Well, if you post to the event_list
page, you execute no less than 11 joins. I wouldn't be surprised if this page always crashes when you POST to it in production, and it's just that hardly anyone ever causes a POST. See https://github.com/tbpmig/mig-website/blob/master/event_cal/views.py#L1169
Essentially, everytime you access one of those subfields, you're incurring at least one JOIN.
Yup. This filter will crash it reliably.
Ah ok, I had to date not been able to get a query to crash it. Any suggestions on how to go about doing that kind of complex querying in a manner that doesn't borke the whole thing?
Michael Hand Electrical Engineering/Control Systems M.S.E. The University of Michigan mikehand@umich.edu
On Mon, Feb 8, 2016 at 10:33 PM, David Adrian notifications@github.com wrote:
Yup. This filter will crash it reliably.
[image: screen shot 2016-02-08 at 10 32 18 pm] https://cloud.githubusercontent.com/assets/1158264/12906977/f4f96d9e-ceb3-11e5-9f71-c1afaaa7099a.png
— Reply to this email directly or view it on GitHub https://github.com/tbpmig/mig-website/issues/206#issuecomment-181690666.
Filter by shifts, then group by events, then join. Essentially, do what you're doing but in reverse.
Effectively, this page is also using up all the memory on the server as well (the database may also be contributing while processing this query). See the latest error message.
Internal Server Error: /calendar/event_list/
Traceback (most recent call last):
File "/home/webdev/.virtualenvs/migweb/lib/python2.7/site-packages/django/core/handlers/base.py", line 111, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/srv/www/event_cal/views.py", line 1209, in list
query_event_type = category.get_children(query_event_type)
File "/srv/www/requirements/models.py", line 202, in get_children
query |= child.get_children(query)
File "/home/webdev/.virtualenvs/migweb/lib/python2.7/site-packages/django/db/models/query_utils.py", line 58, in __or__
return self._combine(other, self.OR)
File "/home/webdev/.virtualenvs/migweb/lib/python2.7/site-packages/django/db/models/query_utils.py", line 53, in _combine
obj.add(self, conn)
File "/home/webdev/.virtualenvs/migweb/lib/python2.7/site-packages/django/utils/tree.py", line 119, in add
self.children.extend(data.children)
MemoryError
Also, FWIW, the UI on the event_list page is awful.
So @dadrian assuming the queries are rewritten as appropriate. This should fix it?
shifts = EventShift.objects.filter(query_date & query_location & q_can_attend)
events = CalendarEvent.objects.filter(
query_members &
query_event_type
)
events = events.filter(eventshift__in=shifts).distinct()
Oh wait, it's actually the query_event_type
that's causing it to crash, even if the other sorting has happened. Assumedly because of how it checks A | B | C | D | etc.
All of the OR statements require a JOIN, because you're looking into the eventshift itself, rather than the event. Is there someway you could select all eventshifts, and then filter those?
So the view actually looks through events rather than shifts. The event_category
attribute is on the CalendarEvent objects. The problematic part is that I'm trying to find events that will satisfy any one of those event types. Doing all the advance filtering on shifts and other things doesn't cause issues.
There must be a clean, efficient way of doing this. It would seem that simply looping through all the candidate pre-filtered events and checking if it satisfies any of those would actually work without issue
Yes, the view looks through events, but every time you filter on eventshift__some_property
you're doing a join of events against event shifts.
I removed the filtering across shift relationships (not yet committed) and it still is crashing
The issue seems to be the
events.filter(event_type=(A OR B OR C OR ...))
part.
Send me a link to the relevant code? I'll try to DBA this shit.
It's in event_cal/views.py
The list function
On Monday, February 15, 2016, Kyle Lady notifications@github.com wrote:
Send me a link to the relevant code? I'll try to DBA this shit.
— Reply to this email directly or view it on GitHub https://github.com/tbpmig/mig-website/issues/206#issuecomment-184217706.
Michael Hand Electrical Engineering/Control Systems M.S.E. The University of Michigan mikehand@umich.edu
Dude that's not even the right view. Sure it's a tragedy against basic coding, but it works, and it doesn't cause performance issues at the moment.
Michael Hand Electrical Engineering/Control Systems M.S.E. The University of Michigan mikehand@umich.edu
On Wed, Feb 17, 2016 at 7:12 AM, Kyle Lady notifications@github.com wrote:
— Reply to this email directly or view it on GitHub https://github.com/tbpmig/mig-website/issues/206#issuecomment-185174059.
I know.
Sure it's a tragedy against basic coding
This entire website is a tragedy against basic coding principles
Yeah but it's my tragedy against basic coding
On Wednesday, February 17, 2016, David Adrian notifications@github.com wrote:
Sure it's a tragedy against basic coding
This entire website is a tragedy against basic coding principles
— Reply to this email directly or view it on GitHub https://github.com/tbpmig/mig-website/issues/206#issuecomment-185524584.
Michael Hand Electrical Engineering/Control Systems M.S.E. The University of Michigan mikehand@umich.edu
Seems to be (possibly) related to the event_list page