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

Kmesh ads mode cluster add consistent hash lb #888

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

bfforever
Copy link
Member

@bfforever bfforever commented Sep 23, 2024

What type of PR is this?
/kind feature

What this PR does / why we need it:

Which issue(s) this PR fixes:
proposal

Special notes for your reviewer:

Does this PR introduce a user-facing change?:


@kmesh-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign kevin-wangzefeng for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@@ -0,0 +1,204 @@
package maglev
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add copyright

@@ -0,0 +1,176 @@
package maglev
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

"unsafe"

"github.com/cilium/ebpf"
"github.com/stretchr/testify/suite"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a blank line to separate Kmesh pkgs from other pkgs.

@@ -11,6 +11,8 @@
#include "endpoint/endpoint.pb-c.h"

#define CLUSTER_NAME_MAX_LEN BPF_DATA_MAX_LEN
#define MAGLEV_TABLE_SIZE 16381
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is table size set to this?

BPF_LOG(INFO, CLUSTER, "lb_policy is maglev, got a hash value:%u\n", hash);
}
index = hash % MAGLEV_TABLE_SIZE;
if (index >= MAGLEV_TABLE_SIZE)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will index is greater than MAGLEV_TABLE_SIZE after the % operation?

if (index >= MAGLEV_TABLE_SIZE)
return NULL;
id = map_array_get_32(backend_ids, index, MAGLEV_TABLE_SIZE);
BPF_LOG(INFO, CLUSTER, "lb_policy is maglev, select backend id:%u\n", id);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think this log is unnecessary.


##### maglev lookup table
Use a compact table, table entry is bit width of endpoint count.
For the table size default is 16381.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reference here?

}

func InitMaglevMap() error {
log.Println("InitMaglevMap")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove

__uint(map_flags, BPF_F_NO_PREALLOC);
__array(values, struct inner_of_maglev);
} outer_of_maglev SEC(".maps");

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to use the outer-inner map structure here?

if (!msg_header_len)
return hash;

BPF_LOG(INFO, ROUTER_CONFIG, "Got a header value len:%u\n", msg_header_len);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove or change to debug level

BPF_LOG(INFO, ROUTER_CONFIG, "Got a header value len:%u\n", msg_header_len);
if (!bpf_strncpy(msg_header_cp, msg_header_len, msg_header_v))
return hash;
BPF_LOG(INFO, ROUTER_CONFIG, "Got a header value:%s\n", msg_header_cp);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

if (!bpf_strncpy(msg_header_cp, msg_header_len, msg_header_v))
return hash;
BPF_LOG(INFO, ROUTER_CONFIG, "Got a header value:%s\n", msg_header_cp);
hash = 5318;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5318 mean ?

MaglevOuterMapName = "outer_of_maglev"
MaglevInnerMapName = "inner_of_maglev"
MaglevMapMaxEntries = 65536
ClusterNameMaxLen = 192
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep consistent with ebpf c code

return (b.offset + (b.skip * b.next)) % maglevTableSize
}

func getLookupTable(cluster *cluster_v2.Cluster, tableSize uint64) ([]int, error) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a source ref.

// sk->protocol, HASH_INIT4_SEED);
// }

static __always_inline __u32 map_array_get_32(__u32 *array, __u32 index, const __u32 limit)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a source ref.

__uint(value_size, sizeof(__u32));
__uint(max_entries, 1);
} map_of_lb_hash SEC(".maps");

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a describe comment to this map.


static inline int map_add_lb_hash(__u32 hash)
{
int location = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that key conflicts exist. different sockets use the same key, and records may be overwritten.

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

Successfully merging this pull request may close these issues.

5 participants