@cocreate/server-autoscaler 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/automated.yml +1 -1
- package/CHANGELOG.md +7 -0
- package/README.md +139 -55
- package/package.json +13 -10
- package/release.config.js +1 -1
- package/src/geoScaling.js +223 -0
- package/src/index.js +305 -364
- package/src/test.js +113 -0
package/src/test.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import getCloudProvider from './geoScaling.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Mock dataset of active client connections with geographic telemetry
|
|
5
|
+
* (50% Northern Europe, 25% Northern Africa, 25% Middle East).
|
|
6
|
+
*/
|
|
7
|
+
export const MOCK_CLIENTS = [
|
|
8
|
+
// Northern Europe Cluster (50% total load)
|
|
9
|
+
{
|
|
10
|
+
clientInfo: {
|
|
11
|
+
latitude: 59.3293,
|
|
12
|
+
longitude: 18.0686,
|
|
13
|
+
countryCode: 'SE',
|
|
14
|
+
timezone: 'Europe/Stockholm'
|
|
15
|
+
},
|
|
16
|
+
count: 20
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
clientInfo: {
|
|
20
|
+
latitude: 50.1109,
|
|
21
|
+
longitude: 8.6821,
|
|
22
|
+
countryCode: 'DE',
|
|
23
|
+
timezone: 'Europe/Berlin'
|
|
24
|
+
},
|
|
25
|
+
count: 15
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
clientInfo: {
|
|
29
|
+
latitude: 51.5074,
|
|
30
|
+
longitude: -0.1278,
|
|
31
|
+
countryCode: 'GB',
|
|
32
|
+
timezone: 'Europe/London'
|
|
33
|
+
},
|
|
34
|
+
count: 15
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
// Northern Africa Cluster (25% total load)
|
|
38
|
+
{
|
|
39
|
+
clientInfo: {
|
|
40
|
+
latitude: 30.0444,
|
|
41
|
+
longitude: 31.2357,
|
|
42
|
+
countryCode: 'EG',
|
|
43
|
+
timezone: 'Africa/Cairo'
|
|
44
|
+
},
|
|
45
|
+
count: 15
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
clientInfo: {
|
|
49
|
+
latitude: 33.5731,
|
|
50
|
+
longitude: -7.5898,
|
|
51
|
+
countryCode: 'MA',
|
|
52
|
+
timezone: 'Africa/Casablanca'
|
|
53
|
+
},
|
|
54
|
+
count: 10
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
// Middle East Cluster (25% total load)
|
|
58
|
+
{
|
|
59
|
+
clientInfo: {
|
|
60
|
+
latitude: 25.2048,
|
|
61
|
+
longitude: 55.2708,
|
|
62
|
+
countryCode: 'AE',
|
|
63
|
+
timezone: 'Asia/Dubai'
|
|
64
|
+
},
|
|
65
|
+
count: 15
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
clientInfo: {
|
|
69
|
+
latitude: 24.7136,
|
|
70
|
+
longitude: 46.6753,
|
|
71
|
+
countryCode: 'SA',
|
|
72
|
+
timezone: 'Asia/Riyadh'
|
|
73
|
+
},
|
|
74
|
+
count: 10
|
|
75
|
+
}
|
|
76
|
+
];
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Immediate Execution Function (Runs on script load)
|
|
80
|
+
* Evaluates strict continent isolation vs multi-region EMEA aggregation.
|
|
81
|
+
*/
|
|
82
|
+
function runGeoScalingTest() {
|
|
83
|
+
console.log("==================================================");
|
|
84
|
+
console.log("[GeoScaling Test] Scenario: 50% Northern Europe | 25% North Africa | 25% Middle East");
|
|
85
|
+
console.log("==================================================");
|
|
86
|
+
|
|
87
|
+
// Test 1: Strict continent isolation (dominant cluster only)
|
|
88
|
+
console.log("\n--- TEST 1: Strict Continent Isolation (dominantClusterOnly: true) ---");
|
|
89
|
+
const strictResult = getCloudProvider(MOCK_CLIENTS, { dominantClusterOnly: true });
|
|
90
|
+
|
|
91
|
+
if (strictResult && strictResult.nearestCloudRegion) {
|
|
92
|
+
console.log(`- Dominant Continent: ${strictResult.dominantContinent} (${strictResult.dominantPercentage}% of load)`);
|
|
93
|
+
console.log(`- Matched Datacenter: ${strictResult.nearestCloudRegion.provider.toUpperCase()} ${strictResult.nearestCloudRegion.region} (${strictResult.nearestCloudRegion.datacenterName})`);
|
|
94
|
+
console.log(`- Regional Centroid Coords: (${strictResult.regionalCentroid.lat.toFixed(4)}, ${strictResult.regionalCentroid.lng.toFixed(4)})`);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Test 2: Combined Macro-Region / Centroid (EMEA unified cluster)
|
|
98
|
+
console.log("\n--- TEST 2: Combined EMEA / Inter-continental Centroid (dominantClusterOnly: false) ---");
|
|
99
|
+
const combinedResult = getCloudProvider(MOCK_CLIENTS, { dominantClusterOnly: false });
|
|
100
|
+
|
|
101
|
+
if (combinedResult && combinedResult.nearestCloudRegion) {
|
|
102
|
+
console.log(`- Global EMEA Centroid Coords: (${combinedResult.globalCentroid.lat.toFixed(4)}, ${combinedResult.globalCentroid.lng.toFixed(4)})`);
|
|
103
|
+
console.log(`- Matched Datacenter: ${combinedResult.nearestCloudRegion.provider.toUpperCase()} ${combinedResult.nearestCloudRegion.region} (${combinedResult.nearestCloudRegion.datacenterName})`);
|
|
104
|
+
console.log(`- Balanced Centroid Distance: ${combinedResult.nearestCloudRegion.distanceKm} km`);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return { strictResult, combinedResult };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Execute on script load
|
|
111
|
+
const autoRunResult = runGeoScalingTest();
|
|
112
|
+
|
|
113
|
+
export default autoRunResult;
|