potential performance issue when scheduling network segments

Bug #1959750 reported by Sahid Orentino
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
neutron
Fix Released
Low
Sahid Orentino

Bug Description

During some investigations regarding segments we may have noticed performance issues related to the current algorithm that schedules network segments on hosts.

When an agent is reporting a change in segment, the process goes to the function `auto_schedule_new_network_segments` with the list of the segments that this host handles.

This function is retrieving from the segments the related networks, then we can notice that the algorithm is running a double for loop. That one iterates through network and per segments to schedule network segments on all hosts.

        for network_id in network_ids:
            for segment in segments:
                self._schedule_network(
                    payload.context, network_id, dhcp_notifier,
                        candidate_hosts=segment['hosts'])

Depending on the design chosen, in a setup that has hundred segments per host with hundred networks and potentially segments that share the same list of hosts, we will endup by calling _schedule_network 10000 times with duplication.

To avoid such duplication and unnecessary calls of _schedule_network for the same hosts we may want to provide a datastructure that is storing for each network the hosts already scheduled.

     for network_id in network_ids:
         for segment in segments:
             if not _already_scheduled(network_id, segment['hosts']):
                 self._schedule_network(
                     payload.context, network_id, dhcp_notifier,
                     candidate_hosts=segment['hosts'])

With this same scenario, and by using such algorithm we may reduce the number of call per the number of networks, 100.

Thanks,
s.

Revision history for this message
Lajos Katona (lajos-katona) wrote :

Thanks for the bug report, do you have perhaps time to implement this solution?

tags: added: loa
tags: added: loadimpact
removed: loa
Revision history for this message
Rodolfo Alonso (rodolfo-alonso-hernandez) wrote :

Hello Sahid:

Good catch.

The segments belong to a single network only. You can use this field to execute or not the scheduling:

        for network_id in network_ids:
            for segment in (s for s in segments if s['network_id'] == network_id):
                self._schedule_network(
                    payload.context, network_id, dhcp_notifier,
                    candidate_hosts=segment['hosts'])

In each "network_id" loop, only those segments belonging to this network will be scheduled; each segment will be scheduled only once.

Thanks again for the bug report.

Regards.

tags: added: low-
tags: added: low-hanging-fruit
removed: low-
Changed in neutron:
importance: Undecided → Low
status: New → Confirmed
Changed in neutron:
assignee: nobody → Sahid Orentino (sahid-ferdjaoui)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to neutron (master)

Fix proposed to branch: master
Review: https://review.opendev.org/c/openstack/neutron/+/829022

Changed in neutron:
status: Confirmed → In Progress
Revision history for this message
Sahid Orentino (sahid-ferdjaoui) wrote (last edit ):

With this patch we reduced the number off calls from about 1 000 000 to 1 000 that *only* for one neutron server.

This has real impact on infratructure.

This is also related to this bug https://bugs.launchpad.net/neutron/+bug/1952730 Where the proposed fix was to avoid this loop to happen but did not fixed the real root cause.

It's also related to that one, and should close that bug I guess.

https://bugs.launchpad.net/neutron/+bug/1951010

@lajos-katona, @rodolfo-alonso-hernandez, my feeling is that we should have this patch as backport potential and have it with highy priority.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to neutron (master)

Reviewed: https://review.opendev.org/c/openstack/neutron/+/829022
Committed: https://opendev.org/openstack/neutron/commit/b5b519a4faa52677d5b9d5553217ed40aac70483
Submitter: "Zuul (22348)"
Branch: master

commit b5b519a4faa52677d5b9d5553217ed40aac70483
Author: Sahid Orentino Ferdjaoui <email address hidden>
Date: Mon Feb 14 13:52:10 2022 +0100

    segments: fix scheduling duplicate segments

    It has been reported by bug #1959750 that for a given network the
    agent is scheduling all segments reported by agent.

    This commit is fixing the issue by ensuring scheduling segments per
    network that they belong to only.
    A test has been updated to demonstract the fact that for a given
    network we only schedule the related segments.

    Closes-bug: #1959750
    Signed-off-by: Sahid Orentino Ferdjaoui <email address hidden>
    Change-Id: Icd57570004055903c6817a75d814ed65db3fa53c

Changed in neutron:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to neutron (stable/xena)

Fix proposed to branch: stable/xena
Review: https://review.opendev.org/c/openstack/neutron/+/829956

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to neutron (stable/wallaby)

Fix proposed to branch: stable/wallaby
Review: https://review.opendev.org/c/openstack/neutron/+/829957

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to neutron (stable/victoria)

Fix proposed to branch: stable/victoria
Review: https://review.opendev.org/c/openstack/neutron/+/829958

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to neutron (stable/xena)

Reviewed: https://review.opendev.org/c/openstack/neutron/+/829956
Committed: https://opendev.org/openstack/neutron/commit/691496c365c6a8d6931b6a839b54ac74a741cd6a
Submitter: "Zuul (22348)"
Branch: stable/xena

commit 691496c365c6a8d6931b6a839b54ac74a741cd6a
Author: Sahid Orentino Ferdjaoui <email address hidden>
Date: Mon Feb 14 13:52:10 2022 +0100

    segments: fix scheduling duplicate segments

    It has been reported by bug #1959750 that for a given network the
    agent is scheduling all segments reported by agent.

    This commit is fixing the issue by ensuring scheduling segments per
    network that they belong to only.
    A test has been updated to demonstract the fact that for a given
    network we only schedule the related segments.

    Closes-bug: #1959750
    Signed-off-by: Sahid Orentino Ferdjaoui <email address hidden>
    Change-Id: Icd57570004055903c6817a75d814ed65db3fa53c
    (cherry picked from commit b5b519a4faa52677d5b9d5553217ed40aac70483)

tags: added: in-stable-xena
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to neutron (stable/victoria)

Reviewed: https://review.opendev.org/c/openstack/neutron/+/829958
Committed: https://opendev.org/openstack/neutron/commit/d06384867f693b0a656dac010906b085897c05ac
Submitter: "Zuul (22348)"
Branch: stable/victoria

commit d06384867f693b0a656dac010906b085897c05ac
Author: Sahid Orentino Ferdjaoui <email address hidden>
Date: Mon Feb 14 13:52:10 2022 +0100

    segments: fix scheduling duplicate segments

    It has been reported by bug #1959750 that for a given network the
    agent is scheduling all segments reported by agent.

    This commit is fixing the issue by ensuring scheduling segments per
    network that they belong to only.
    A test has been updated to demonstract the fact that for a given
    network we only schedule the related segments.

    Closes-bug: #1959750
    Signed-off-by: Sahid Orentino Ferdjaoui <email address hidden>
    Change-Id: Icd57570004055903c6817a75d814ed65db3fa53c
    (cherry picked from commit b5b519a4faa52677d5b9d5553217ed40aac70483)

tags: added: in-stable-victoria
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to neutron (stable/wallaby)

Reviewed: https://review.opendev.org/c/openstack/neutron/+/829957
Committed: https://opendev.org/openstack/neutron/commit/276f1541580c4b36b583d3d4bce76e2c44e00515
Submitter: "Zuul (22348)"
Branch: stable/wallaby

commit 276f1541580c4b36b583d3d4bce76e2c44e00515
Author: Sahid Orentino Ferdjaoui <email address hidden>
Date: Mon Feb 14 13:52:10 2022 +0100

    segments: fix scheduling duplicate segments

    It has been reported by bug #1959750 that for a given network the
    agent is scheduling all segments reported by agent.

    This commit is fixing the issue by ensuring scheduling segments per
    network that they belong to only.
    A test has been updated to demonstract the fact that for a given
    network we only schedule the related segments.

    Closes-bug: #1959750
    Signed-off-by: Sahid Orentino Ferdjaoui <email address hidden>
    Change-Id: Icd57570004055903c6817a75d814ed65db3fa53c
    (cherry picked from commit b5b519a4faa52677d5b9d5553217ed40aac70483)

tags: added: in-stable-wallaby
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/neutron 20.0.0.0rc1

This issue was fixed in the openstack/neutron 20.0.0.0rc1 release candidate.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/neutron 17.4.0

This issue was fixed in the openstack/neutron 17.4.0 release.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/neutron 18.3.0

This issue was fixed in the openstack/neutron 18.3.0 release.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/neutron 19.2.0

This issue was fixed in the openstack/neutron 19.2.0 release.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.