Skip to content

Commit

Permalink
Support for filtering provider offers by golem.inf.cpu.threads and go…
Browse files Browse the repository at this point in the history
…lem.inf.cpu.cores (#231)
  • Loading branch information
filipgolem authored Jul 2, 2021
1 parent 572210d commit 6da7d3d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions yajsapi/package/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type RepoOpts = {
image_hash: string;
min_mem_gib: number;
min_storage_gib: number;
min_cpu_threads?: number;
};

export class Constraints {
Expand Down
6 changes: 5 additions & 1 deletion yajsapi/package/vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class _VmConstrains extends Constraints {
constructor(
min_mem_gib: number,
min_storage_gib: number,
min_cpu_threads: number = 1,
cores: number = 1
) {
super();
Expand All @@ -13,6 +14,7 @@ class _VmConstrains extends Constraints {
`(${InfVmKeys["mem"]}>=${min_mem_gib})`,
`(${InfVmKeys["storage"]}>=${min_storage_gib})`,
`(${InfVmKeys["runtime"]}=${RuntimeType.VM})`,
`(${InfVmKeys["threads"]}>=${min_cpu_threads})`,
]);
}
}
Expand All @@ -21,19 +23,21 @@ export async function repo({
image_hash,
min_mem_gib = 0.5,
min_storage_gib = 2.0,
min_cpu_threads = 1,
}: RepoOpts): Promise<Package> {
/*
Builds reference to a demand decorator.
- *image_hash*: finds package by its contents hash.
- *min_mem_gib*: minimal memory required to execute application code.
- *min_storage_gib* minimal disk storage to execute tasks.
- *min_cpu_threads*: minimal available logical CPU cores (CPU threads).
*/

return new VmPackage({
repo_url: await resolve_repo_srv({repo_srv: DEFAULT_REPO_SRV}),
image_hash,
constraints: new _VmConstrains(min_mem_gib, min_storage_gib),
constraints: new _VmConstrains(min_mem_gib, min_storage_gib, min_cpu_threads),
});
}
4 changes: 3 additions & 1 deletion yajsapi/props/inf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Field, Model } from "./base";
export const INF_MEM: string = "golem.inf.mem.gib";
export const INF_STORAGE: string = "golem.inf.storage.gib";
export const INF_CORES: string = "golem.inf.cpu.cores";
export const INF_THREADS: string = "golem.inf.cpu.threads";
export const INF_RUNTIME: string = "golem.runtime.name";
export const TRANSFER_CAPS: string = "golem.activity.caps.transfer.protocol";

Expand All @@ -19,6 +20,7 @@ export enum RuntimeType {

export class InfBase {
cores: Field = new Field({ metadata: { key: INF_CORES } });
threads: Field = new Field({ metadata: { key: INF_THREADS } });
mem: Field = new Field({ metadata: { key: INF_MEM } });
runtime: Field = new Field({ metadata: { key: INF_RUNTIME } });

Expand All @@ -38,7 +40,7 @@ export class InfVm extends InfBase {
}
export const InfVmKeys = InfBase.fields(
new InfVm(),
["cores", "mem", "storage", "runtime"]
["cores", "mem", "storage", "runtime", "threads"]
);

function getFields(obj: object, keys: string[]) {
Expand Down

0 comments on commit 6da7d3d

Please sign in to comment.