Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

O365 Long Load time #269

Open
VanWardawg opened this issue Feb 22, 2025 · 11 comments
Open

O365 Long Load time #269

VanWardawg opened this issue Feb 22, 2025 · 11 comments

Comments

@VanWardawg
Copy link

I'm using this integration to manage my o365 calendars and display them for my family. I've followed this guidance to make an awesome dashboard (https://community.home-assistant.io/t/diy-family-calendar-skylight/844830) but when applying filters on the m365 calendar entities it takes a really long time. Even when I just open up the default home assistant dashboard it takes a long time to load. Is there a way to optimize the behavior to improve load/reload times?

Thanks,
Kevin Hinton

@RogerSelwyn
Copy link
Owner

Is it that HA is slow to startup and you get errors displayed in the logs saying it is taking too long, or that your dashboard is slow to load?

If it is the dashboard, I'm afraid I can't help, I don't do dashboard development. If it is HA reporting errors, then the likely answer is to pull less data. You would need to provide details on your config of the o365/ms365_calendar to enable me to provide any guidance.

@VanWardawg
Copy link
Author

It doesn't matter the dashboard or calendar card, it seems to be in the query of the API. Does it cache the events at all? My config is just based on the default I followed when I set it up

@RogerSelwyn RogerSelwyn changed the title 0365 Long Load time O365 Long Load time Feb 22, 2025
@RogerSelwyn
Copy link
Owner

Assuming you are using MS365_calendar, (if not please migrate to it), then I have added some extra debugging that will show the start and end of any update. So, install ms365_calendar v1.4.0, then enable debug logging (which you can do from the integration page), and you will see the time taken and the calls that are being performed by the O365 library, in the full log. This should help diagnose the issue for you.

@VanWardawg
Copy link
Author

VanWardawg commented Feb 22, 2025

I'll try that, however I can only find v1.3.1, is that expected?

@VanWardawg
Copy link
Author

I see a lot of lines:

2025-02-22 12:08:23.749 WARNING (MainThread) [homeassistant.helpers.entity] Update of calendar.m365_calendar_{name} is taking over 10 seconds
2025-02-22 12:10:23.750 WARNING (MainThread) [homeassistant.helpers.entity] Update of calendar.m365_calendar_your_family is taking over 10 seconds

some of these: The token needs to be in JWS or JWE Compact Serialization Format. (JWS): 'EncodedHeader.EncodedPayload.EncodedSignature'. (JWE): 'EncodedProtectedHeader.EncodedEncryptedKey.EncodedInitializationVector.EncodedCiphertext.EncodedAuthenticationTag'.
2025-02-22 12:07:14.055 WARNING (MainThread) [custom_components.ms365_calendar.integration.calendar_integration] Error getting calendar events for day - 401 Client Error: Unauthorized for url: {graph url}

some of these:
Error handling request from 127.0.0.1
Traceback (most recent call last):
File "/usr/local/lib/python3.13/site-packages/aiohttp/web_protocol.py", line 480, in _handle_request
resp = await request_handler(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.13/site-packages/aiohttp/web_app.py", line 569, in _handle
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.13/site-packages/aiohttp/web_middlewares.py", line 117, in impl
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 92, in security_filter_middleware
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 77, in forwarded_middleware
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 26, in request_context_middleware
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 86, in ban_middleware
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 242, in auth_middleware
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 32, in headers_middleware
response = await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/http.py", line 73, in handle
result = await handler(request, **request.match_info)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/calendar/init.py", line 656, in get
calendar_event_list = await entity.async_get_events(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...<3 lines>...
)
^
File "/config/custom_components/ms365_calendar/integration/calendar_integration.py", line 288, in async_get_events
return await self.data.async_get_events(hass, start_date, end_date)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/ms365_calendar/integration/calendar_integration.py", line 659, in async_get_events
results = await self.async_ms365_get_events(hass, start_date, end_date)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/ms365_calendar/integration/calendar_integration.py", line 580, in async_ms365_get_events
events = await self._async_calendar_schedule_get_events(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
hass, self.calendar, start_date, end_date, limit
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/config/custom_components/ms365_calendar/integration/calendar_integration.py", line 648, in _async_calendar_schedule_get_events
return await hass.async_add_executor_job(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...<6 lines>...
)
^

2025-02-22 14:14:16.596 WARNING (SyncWorker_8) [urllib3.connectionpool] Connection pool is full, discarding connection: graph.microsoft.com. Connection pool size: 10
2025-02-22 14:14:16.610 WARNING (SyncWorker_38) [urllib3.connectionpool] Connection pool is full, discarding connection: graph.microsoft.com. Connection pool size: 10
2025-02-22 14:14:16.842 WARNING (SyncWorker_23) [urllib3.connectionpool] Connection pool is full, discarding connection: graph.microsoft.com. Connection pool size: 10

A bunch of request and responses from the graph api
some sleeps for several ms: [O365.connection] Sleeping for 200.0 milliseconds
2025-02-22 15:19:01.631 DEBUG (SyncWorker_38) [O365.connection] Sleeping for 200.0 milliseconds
2025-02-22 15:19:01.632 DEBUG (SyncWorker_6) [O365.connection] Sleeping for 200.0 milliseconds

lots and lots of calendar get events (I have 8 calendars, 1 for each member of the family and a couple of misc ones)

@VanWardawg
Copy link
Author

I'm running this on the home assistant green. and all my calendars are configured like this:
entities:

  • device_id: Calendar
    end_offset: 24
    name: Calendar
    start_offset: 0
    track: true

@RogerSelwyn
Copy link
Owner

The fact that you are getting connection pool errors suggests it is trying to do too much. I would split those calendars across two instances of the integration. You can install again with the same details, just enable different sets of calendars against each instance.

@RogerSelwyn
Copy link
Owner

I'm running this on the home assistant green. and all my calendars are configured like this: entities:

  • device_id: Calendar
    end_offset: 24
    name: Calendar
    start_offset: 0
    track: true

I really don't know what the spec of a green is or what it can do. You'd have to do some hardware monitoring to see if it is overloaded. I do run a pi for a minor instance, my main instance is a Mac Mini M1 vm, because right back at the beginning a pi wasn't up to the job.

@VanWardawg
Copy link
Author

hmm ok that is probably important, I'll try spliting them up and see what resources its taking. thanks!

@RogerSelwyn
Copy link
Owner

As an fyi, I'm working a way of reducing the number of calls the integration makes for each update every 30 seconds. I'm changing it from 2 to 1 for each calendar.

@RogerSelwyn
Copy link
Owner

RogerSelwyn commented Feb 23, 2025

It looks to me like that planner dashboard will try to retrieve all of your calendars every time it feels it needs to refresh. Currently that means it will go back to ms 365 to re-retrieve them every time.

The change I have proposed above won't help that. The only thing that will likely help is for the events to be cached, which doesn't currently happen and would be a major change, if it can even be done.

Given the set of data that needs to be cached is not clear cut, for instance you can page backwards/forwards by months with no limit, and it needs to be updated regularly it is a major undertaking.

You may find that trying to manage 10+ calendars in one go is too much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants