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

Drop maxAgreements #953

Merged
merged 2 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions examples/advanced/hello-world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { pinoPrettyLogger } from "@golem-sdk/pino-logger";
expirationSec: 30 * 60,
},
market: {
maxAgreements: 1,
rentHours: 0.5,
pricing: {
model: "linear",
Expand All @@ -38,7 +37,7 @@ import { pinoPrettyLogger } from "@golem-sdk/pino-logger";
});

const allocation = await glm.payment.createAllocation({
budget: glm.market.estimateBudget(order),
budget: glm.market.estimateBudget({ order, concurrency: 1 }),
expirationSec: 60 * 60, // 60 minutes
});
const demandSpecification = await glm.market.buildDemandDetails(order.demand, allocation);
Expand Down
1 change: 0 additions & 1 deletion examples/advanced/payment-filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const order: MarketOrderSpec = {
workload: { imageTag: "golem/alpine:latest" },
},
market: {
maxAgreements: 1,
rentHours: 0.5,
pricing: {
model: "linear",
Expand Down
1 change: 0 additions & 1 deletion examples/advanced/proposal-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const order: MarketOrderSpec = {
workload: { imageTag: "golem/alpine:latest" },
},
market: {
maxAgreements: 1,
rentHours: 0.5,
pricing: {
model: "linear",
Expand Down
1 change: 0 additions & 1 deletion examples/advanced/proposal-predefined-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const order: MarketOrderSpec = {
workload: { imageTag: "golem/alpine:latest" },
},
market: {
maxAgreements: 1,
rentHours: 0.5,
pricing: {
model: "linear",
Expand Down
1 change: 0 additions & 1 deletion examples/basic/many-of.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const order: MarketOrderSpec = {
workload: { imageTag: "golem/alpine:latest" },
},
market: {
maxAgreements: 1,
rentHours: 0.5,
pricing: {
model: "linear",
Expand Down
1 change: 0 additions & 1 deletion examples/basic/one-of.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const order: MarketOrderSpec = {
workload: { imageTag: "golem/alpine:latest" },
},
market: {
maxAgreements: 1,
rentHours: 0.5,
pricing: {
model: "linear",
Expand Down
1 change: 0 additions & 1 deletion examples/basic/run-and-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const order: MarketOrderSpec = {
workload: { imageTag: "golem/alpine:latest" },
},
market: {
maxAgreements: 1,
rentHours: 0.5,
pricing: {
model: "linear",
Expand Down
1 change: 0 additions & 1 deletion examples/basic/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const order: MarketOrderSpec = {
workload: { imageTag: "golem/alpine:latest" },
},
market: {
maxAgreements: 2,
rentHours: 0.5,
pricing: {
model: "linear",
Expand Down
1 change: 0 additions & 1 deletion examples/basic/vpn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { pinoPrettyLogger } from "@golem-sdk/pino-logger";
workload: { imageTag: "golem/alpine:latest" },
},
market: {
maxAgreements: 2,
rentHours: 0.5,
pricing: {
model: "linear",
Expand Down
2 changes: 0 additions & 2 deletions examples/experimental/deployment/new-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ async function main() {
},
},
market: {
maxAgreements: 2,
rentHours: 12,
pricing: {
model: "linear",
Expand Down Expand Up @@ -53,7 +52,6 @@ async function main() {
},
},
market: {
maxAgreements: 1,
rentHours: 12 /* REQUIRED */,
pricing: {
model: "linear",
Expand Down
1 change: 0 additions & 1 deletion examples/experimental/express/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ app.post("/tts", async (req, res) => {
},
},
market: {
maxAgreements: 1,
rentHours: 0.5,
pricing: {
model: "linear",
Expand Down
1 change: 0 additions & 1 deletion examples/experimental/job/cancel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const order: MarketOrderSpec = {
workload: { imageTag: "severyn/espeak:latest" },
},
market: {
maxAgreements: 1,
rentHours: 0.5,
pricing: {
model: "linear",
Expand Down
1 change: 0 additions & 1 deletion examples/experimental/job/getJobById.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const order: MarketOrderSpec = {
workload: { imageTag: "severyn/espeak:latest" },
},
market: {
maxAgreements: 1,
rentHours: 0.5,
pricing: {
model: "linear",
Expand Down
1 change: 0 additions & 1 deletion examples/experimental/job/waitForResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const order: MarketOrderSpec = {
},
},
market: {
maxAgreements: 1,
rentHours: 0.5,
pricing: {
model: "linear",
Expand Down
10 changes: 7 additions & 3 deletions src/experimental/deployment/builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ describe("Deployment builder", () => {
},
},
market: {
maxAgreements: 1,
rentHours: 1,
pricing: {
model: "linear",
Expand All @@ -29,6 +28,9 @@ describe("Deployment builder", () => {
maxCpuPerHourPrice: 1,
},
},
deployment: {
replicas: 1,
},
})
.createLeaseProcessPool("my-pool", {
demand: {
Expand All @@ -40,7 +42,6 @@ describe("Deployment builder", () => {
},
},
market: {
maxAgreements: 1,
rentHours: 1,
pricing: {
model: "linear",
Expand All @@ -49,6 +50,9 @@ describe("Deployment builder", () => {
maxCpuPerHourPrice: 1,
},
},
deployment: {
replicas: 1,
},
});
}).toThrow(new GolemConfigError(`Lease Process Pool with name my-pool already exists`));
});
Expand Down Expand Up @@ -76,7 +80,6 @@ describe("Deployment builder", () => {
workload: { imageTag: "image", minCpuCores: 1, minMemGib: 1, minStorageGib: 1 },
},
market: {
maxAgreements: 1,
rentHours: 1,
pricing: {
model: "linear",
Expand All @@ -87,6 +90,7 @@ describe("Deployment builder", () => {
},
deployment: {
network: "non-existing-network",
replicas: 1,
},
})
.getDeployment();
Expand Down
4 changes: 2 additions & 2 deletions src/experimental/deployment/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { GolemNetwork, MarketOrderSpec } from "../../golem-network";
import { validateDeployment } from "./validate-deployment";

interface DeploymentOptions {
replicas?: number | { min: number; max: number };
replicas: number | { min: number; max: number };
network?: string;
}

export interface CreateLeaseProcessPoolOptions extends MarketOrderSpec {
deployment?: DeploymentOptions;
deployment: DeploymentOptions;
}

export class GolemDeploymentBuilder {
Expand Down
7 changes: 6 additions & 1 deletion src/experimental/deployment/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,12 @@ export class Deployment {
const longestExpiration =
Math.max(...this.components.leaseProcessPools.map((pool) => pool.options.market.rentHours)) * 3600;
const totalBudget = this.components.leaseProcessPools.reduce(
(acc, pool) => acc + this.modules.market.estimateBudget(pool.options),
(acc, pool) =>
acc +
this.modules.market.estimateBudget({
order: pool.options,
concurrency: pool.options.deployment.replicas,
}),
0,
);

Expand Down
1 change: 0 additions & 1 deletion src/experimental/job/job.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ describe("Job", () => {
},
},
market: {
maxAgreements: 1,
rentHours: 1,
pricing: {
model: "linear",
Expand Down
1 change: 0 additions & 1 deletion src/golem-network/golem-network.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const order: MarketOrderSpec = Object.freeze({
workload: { imageTag: "golem/alpine:latest" },
},
market: {
maxAgreements: 1,
rentHours: 0.5,
pricing: {
model: "linear",
Expand Down
8 changes: 4 additions & 4 deletions src/golem-network/golem-network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { IPaymentApi, PaymentModule, PaymentModuleImpl, PaymentModuleOptions } f
import { ActivityModule, ActivityModuleImpl, IActivityApi, IFileServer } from "../activity";
import { Network, NetworkModule, NetworkModuleImpl, NetworkOptions, INetworkApi } from "../network";
import { EventEmitter } from "eventemitter3";
import { LeaseProcess, LeaseProcessOptions, LeaseProcessPool, LeaseProcessPoolOptions } from "../lease-process";
import { Concurrency, LeaseProcess, LeaseProcessOptions, LeaseProcessPool } from "../lease-process";
import { DebitNoteRepository, InvoiceRepository, MarketApiAdapter, PaymentApiAdapter } from "../shared/yagna";
import { ActivityApiAdapter } from "../shared/yagna/adapters/activity-api-adapter";
import { ActivityRepository } from "../shared/yagna/repository/activity-repository";
Expand Down Expand Up @@ -99,7 +99,7 @@ export interface GolemNetworkEvents {
}

interface ManyOfOptions {
concurrency: LeaseProcessPoolOptions["replicas"];
concurrency: Concurrency;
order: MarketOrderSpec;
}

Expand Down Expand Up @@ -296,7 +296,7 @@ export class GolemNetwork {
logger: this.logger,
});

const budget = this.market.estimateBudget(order);
const budget = this.market.estimateBudget({ order, concurrency: 1 });
const allocation = await this.payment.createAllocation({
budget,
expirationSec: order.market.rentHours * 60 * 60,
Expand Down Expand Up @@ -381,7 +381,7 @@ export class GolemNetwork {
logger: this.logger,
});

const budget = this.market.estimateBudget(order);
const budget = this.market.estimateBudget({ concurrency, order });
const allocation = await this.payment.createAllocation({
budget,
expirationSec: order.market.rentHours * 60 * 60,
Expand Down
4 changes: 3 additions & 1 deletion src/lease-process/lease-process-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ export interface LeaseProcessPoolDependencies {
logger: Logger;
}

export type Concurrency = number | RequireAtLeastOne<{ min: number; max: number }>;

export interface LeaseProcessPoolOptions {
replicas?: number | RequireAtLeastOne<{ min: number; max: number }>;
replicas?: Concurrency;
network?: Network;
leaseProcessOptions?: LeaseProcessOptions;
}
Expand Down
78 changes: 78 additions & 0 deletions src/market/market.module.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Allocation, IPaymentApi } from "../payment";
import { INetworkApi } from "../network/api";
import { NetworkModule } from "../network";
import { DraftOfferProposalPool } from "./draft-offer-proposal-pool";
import { MarketOrderSpec } from "../golem-network";

const mockMarketApiAdapter = mock(MarketApiAdapter);
const mockYagna = mock(YagnaApi);
Expand Down Expand Up @@ -549,4 +550,81 @@ describe("Market module", () => {
expect(marketModule.signAgreementFromPool(mockPool)).rejects.toThrow("Failed to acquire");
});
});
describe("estimateBudget()", () => {
it("estimates budget for the exact concurrency level", () => {
const order: MarketOrderSpec = {
demand: {
workload: {
imageTag: "image",
minCpuThreads: 5,
},
},
market: {
rentHours: 5,
pricing: {
model: "linear",
maxStartPrice: 1,
maxEnvPerHourPrice: 2,
maxCpuPerHourPrice: 0.5,
},
},
};
const concurrency = 3;
const cpuPrice = 0.5 * 5 * 5; // 5 threads for 0.5 per hour for 5 hours
const envPrice = 2 * 5; // 2 per hour for 5 hours
const totalPricePerMachine = 1 + cpuPrice + envPrice;
const expectedBudget = totalPricePerMachine * concurrency;

const budget = marketModule.estimateBudget({ order, concurrency });
expect(budget).toBeCloseTo(expectedBudget, 5);
});
it("estimates budget for max concurrency level", () => {
const order: MarketOrderSpec = {
demand: {
workload: {
imageTag: "image",
minCpuThreads: 5,
},
},
market: {
rentHours: 5,
pricing: {
model: "linear",
maxStartPrice: 1,
maxEnvPerHourPrice: 2,
maxCpuPerHourPrice: 0.5,
},
},
};
const concurrency = { max: 10 };
const cpuPrice = 0.5 * 5 * 5; // 5 threads for 0.5 per hour for 5 hours
const envPrice = 2 * 5; // 2 per hour for 5 hours
const totalPricePerMachine = 1 + cpuPrice + envPrice;
const expectedBudget = totalPricePerMachine * concurrency.max;

const budget = marketModule.estimateBudget({ order, concurrency });
expect(budget).toBeCloseTo(expectedBudget, 5);
});
it("estimates budget for non-linear pricing model", () => {
const order: MarketOrderSpec = {
demand: {
workload: {
imageTag: "image",
},
},
market: {
rentHours: 5,
pricing: {
model: "burn-rate",
avgGlmPerHour: 2,
},
},
};
const concurrency = 3;
const expectedBudget = 5 * 2 * concurrency;

const budget = marketModule.estimateBudget({ order, concurrency });
expect(budget).toBeCloseTo(expectedBudget, 5);
});
});
});
Loading
Loading