mirror of
https://github.com/portainer/portainer.git
synced 2025-08-05 05:45:22 +02:00
fix(edgegroups): convert the related endpoint IDs to roaring bitmaps to increase performance BE-12053 (#903)
This commit is contained in:
parent
caf382b64c
commit
937456596a
32 changed files with 1041 additions and 133 deletions
|
@ -1,8 +1,6 @@
|
|||
package edge
|
||||
|
||||
import (
|
||||
"slices"
|
||||
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
"github.com/portainer/portainer/api/dataservices"
|
||||
"github.com/portainer/portainer/api/internal/endpointutils"
|
||||
|
@ -12,7 +10,7 @@ import (
|
|||
// EdgeGroupRelatedEndpoints returns a list of environments(endpoints) related to this Edge group
|
||||
func EdgeGroupRelatedEndpoints(edgeGroup *portainer.EdgeGroup, endpoints []portainer.Endpoint, endpointGroups []portainer.EndpointGroup) []portainer.EndpointID {
|
||||
if !edgeGroup.Dynamic {
|
||||
return edgeGroup.Endpoints
|
||||
return edgeGroup.EndpointIDs.ToSlice()
|
||||
}
|
||||
|
||||
endpointGroupsMap := map[portainer.EndpointGroupID]*portainer.EndpointGroup{}
|
||||
|
@ -72,7 +70,7 @@ func GetEndpointsFromEdgeGroups(edgeGroupIDs []portainer.EdgeGroupID, datastore
|
|||
// edgeGroupRelatedToEndpoint returns true if edgeGroup is associated with environment(endpoint)
|
||||
func edgeGroupRelatedToEndpoint(edgeGroup *portainer.EdgeGroup, endpoint *portainer.Endpoint, endpointGroup *portainer.EndpointGroup) bool {
|
||||
if !edgeGroup.Dynamic {
|
||||
return slices.Contains(edgeGroup.Endpoints, endpoint.ID)
|
||||
return edgeGroup.EndpointIDs.Contains(endpoint.ID)
|
||||
}
|
||||
|
||||
endpointTags := tag.Set(endpoint.TagIDs)
|
||||
|
|
104
api/internal/edge/edgegroup_benchmark_test.go
Normal file
104
api/internal/edge/edgegroup_benchmark_test.go
Normal file
|
@ -0,0 +1,104 @@
|
|||
package edge
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
"github.com/portainer/portainer/api/datastore"
|
||||
"github.com/portainer/portainer/api/roar"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const n = 1_000_000
|
||||
|
||||
func BenchmarkWriteEdgeGroupOld(b *testing.B) {
|
||||
zerolog.SetGlobalLevel(zerolog.ErrorLevel)
|
||||
|
||||
_, store := datastore.MustNewTestStore(b, false, false)
|
||||
|
||||
var endpointIDs []portainer.EndpointID
|
||||
|
||||
for i := range n {
|
||||
endpointIDs = append(endpointIDs, portainer.EndpointID(i+1))
|
||||
}
|
||||
|
||||
for b.Loop() {
|
||||
err := store.EdgeGroup().Create(&portainer.EdgeGroup{
|
||||
Name: "Test Edge Group",
|
||||
Endpoints: endpointIDs,
|
||||
})
|
||||
require.NoError(b, err)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkWriteEdgeGroupNew(b *testing.B) {
|
||||
zerolog.SetGlobalLevel(zerolog.ErrorLevel)
|
||||
|
||||
_, store := datastore.MustNewTestStore(b, false, false)
|
||||
|
||||
var ts []portainer.EndpointID
|
||||
|
||||
for i := range n {
|
||||
ts = append(ts, portainer.EndpointID(i+1))
|
||||
}
|
||||
|
||||
endpointIDs := roar.FromSlice(ts)
|
||||
|
||||
for b.Loop() {
|
||||
err := store.EdgeGroup().Create(&portainer.EdgeGroup{
|
||||
Name: "Test Edge Group",
|
||||
EndpointIDs: endpointIDs,
|
||||
})
|
||||
require.NoError(b, err)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkReadEdgeGroupOld(b *testing.B) {
|
||||
zerolog.SetGlobalLevel(zerolog.ErrorLevel)
|
||||
|
||||
_, store := datastore.MustNewTestStore(b, false, false)
|
||||
|
||||
var endpointIDs []portainer.EndpointID
|
||||
|
||||
for i := range n {
|
||||
endpointIDs = append(endpointIDs, portainer.EndpointID(i+1))
|
||||
}
|
||||
|
||||
err := store.EdgeGroup().Create(&portainer.EdgeGroup{
|
||||
Name: "Test Edge Group",
|
||||
Endpoints: endpointIDs,
|
||||
})
|
||||
require.NoError(b, err)
|
||||
|
||||
for b.Loop() {
|
||||
_, err := store.EdgeGroup().ReadAll()
|
||||
require.NoError(b, err)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkReadEdgeGroupNew(b *testing.B) {
|
||||
zerolog.SetGlobalLevel(zerolog.ErrorLevel)
|
||||
|
||||
_, store := datastore.MustNewTestStore(b, false, false)
|
||||
|
||||
var ts []portainer.EndpointID
|
||||
|
||||
for i := range n {
|
||||
ts = append(ts, portainer.EndpointID(i+1))
|
||||
}
|
||||
|
||||
endpointIDs := roar.FromSlice(ts)
|
||||
|
||||
err := store.EdgeGroup().Create(&portainer.EdgeGroup{
|
||||
Name: "Test Edge Group",
|
||||
EndpointIDs: endpointIDs,
|
||||
})
|
||||
require.NoError(b, err)
|
||||
|
||||
for b.Loop() {
|
||||
_, err := store.EdgeGroup().ReadAll()
|
||||
require.NoError(b, err)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue