feat(route-optimizer): add configurable download and upload weights for bandwidth scoring in AI settings
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 1m34s
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 1m34s
This commit is contained in:
@@ -15,6 +15,8 @@ const DEFAULT_AI_SETTINGS = {
|
||||
latencyWeight: 0.55,
|
||||
bandwidthWeight: 0.35,
|
||||
freshnessWeight: 0.1,
|
||||
downloadWeight: 0.5,
|
||||
uploadWeight: 0.5,
|
||||
combineHomeToJumphostWeight: 0.45,
|
||||
combineJumphostToExitWeight: 0.55,
|
||||
probabilityScale: 5,
|
||||
@@ -47,6 +49,11 @@ function positiveNumber(v, fallback) {
|
||||
return Number.isFinite(n) && n > 0 ? n : fallback;
|
||||
}
|
||||
|
||||
function nonNegativeNumber(v, fallback) {
|
||||
const n = Number(v);
|
||||
return Number.isFinite(n) && n >= 0 ? n : fallback;
|
||||
}
|
||||
|
||||
function makeServerKey(server) {
|
||||
if (!server || typeof server !== 'object') return '';
|
||||
return String(server.id || server.dns || server.ip || '').trim();
|
||||
@@ -97,10 +104,10 @@ function freshnessScore(cacheUpdatedAt, aiSettings) {
|
||||
}
|
||||
|
||||
function bandwidthScore({ speedDownloadMbps, speedUploadMbps, aiSettings }) {
|
||||
// DL/UL considered separately with equal 50/50 contribution.
|
||||
// DL/UL considered separately with configurable weights.
|
||||
const dl = normalizeBandwidthValue(speedDownloadMbps, aiSettings);
|
||||
const ul = normalizeBandwidthValue(speedUploadMbps, aiSettings);
|
||||
return clamp((dl + ul) / 2, 0, 1);
|
||||
return clamp(dl * aiSettings.downloadWeight + ul * aiSettings.uploadWeight, 0, 1);
|
||||
}
|
||||
|
||||
function buildSegmentScore({
|
||||
@@ -252,6 +259,9 @@ async function loadAiSettings() {
|
||||
const bandwidthWeight = positiveNumber(src.bandwidthWeight, DEFAULT_AI_SETTINGS.bandwidthWeight);
|
||||
const freshnessWeight = positiveNumber(src.freshnessWeight, DEFAULT_AI_SETTINGS.freshnessWeight);
|
||||
const sum = latencyWeight + bandwidthWeight + freshnessWeight || 1;
|
||||
const downloadWeight = nonNegativeNumber(src.downloadWeight, DEFAULT_AI_SETTINGS.downloadWeight);
|
||||
const uploadWeight = nonNegativeNumber(src.uploadWeight, DEFAULT_AI_SETTINGS.uploadWeight);
|
||||
const sumDu = downloadWeight + uploadWeight;
|
||||
const hjW = positiveNumber(
|
||||
src.combineHomeToJumphostWeight,
|
||||
DEFAULT_AI_SETTINGS.combineHomeToJumphostWeight
|
||||
@@ -276,6 +286,8 @@ async function loadAiSettings() {
|
||||
latencyWeight: latencyWeight / sum,
|
||||
bandwidthWeight: bandwidthWeight / sum,
|
||||
freshnessWeight: freshnessWeight / sum,
|
||||
downloadWeight: sumDu > 0 ? downloadWeight / sumDu : DEFAULT_AI_SETTINGS.downloadWeight,
|
||||
uploadWeight: sumDu > 0 ? uploadWeight / sumDu : DEFAULT_AI_SETTINGS.uploadWeight,
|
||||
combineHomeToJumphostWeight: hjW / sum2,
|
||||
combineJumphostToExitWeight: jeW / sum2,
|
||||
probabilityScale: clamp(
|
||||
|
||||
Reference in New Issue
Block a user