Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

limit benchmark-based usage factors #4803

Closed
wants to merge 1 commit into from
Closed
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
16 changes: 13 additions & 3 deletions golem/marketplace/wasm_marketplace.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@
logger = logging.getLogger(__name__)


USAGE_SECOND = 1e9 # usage is measured in nanoseconds


class RequestorWasmMarketStrategy(RequestorPoolingMarketStrategy):
DEFAULT_USAGE_BENCHMARK: float = 1.0
DEFAULT_USAGE_BENCHMARK: float = 1.0 * USAGE_SECOND

_usages: ClassVar[Dict[str, float]] = dict()
_usage_factors: ClassVar[Dict[str, float]] = dict()
Expand All @@ -39,6 +42,8 @@ def get_my_usage_benchmark(cls) -> float:

@classmethod
def set_my_usage_benchmark(cls, benchmark: float) -> None:
if benchmark < 1e-6 * USAGE_SECOND:
benchmark = cls.DEFAULT_USAGE_BENCHMARK
logger.info("RWMS: set_my_usage_benchmark %.3f", benchmark)
cls._my_usage_benchmark = benchmark

Expand All @@ -49,8 +54,13 @@ def get_usage_factor(cls, provider_id, usage_benchmark):
# Division goes this way since higher benchmark val means
# faster processor
usage_factor = cls.get_my_usage_benchmark() / usage_benchmark
if not usage_factor:
usage_factor = 1.0

# Sanity check against misreported benchmarks
usage_factor = min(max(usage_factor, 0.25), 1.5)
Copy link
Contributor

Choose a reason for hiding this comment

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

why are we assuming that the usage cannot be farther away than that from our own? can't a really slow or really fast CPU have such - out of range - results?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It can, but if it is, it will be caught by the usage factor adjustment. It may make sense to widen the limits though.

logger.info("RWMS: initial usage factor for %s = %.3f",
provider_id,
usage_factor)

cls._usage_factors[provider_id] = usage_factor
return usage_factor

Expand Down
16 changes: 12 additions & 4 deletions tests/golem/marketplace/test_wasm_marketplace.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from golem.marketplace import ProviderPerformance
from golem.marketplace.wasm_marketplace import RequestorWasmMarketStrategy

USAGE_SECOND = 1e9 # usage is measured in nanoseconds


class TestOfferChoice(TestCase):
TASK_1 = 'task_1'
Expand All @@ -21,23 +23,29 @@ def setUp(self):
mock_offer_1.quality = (.0, .0, .0, .0)
mock_offer_1.reputation = .0
mock_offer_1.price = 5.0
mock_offer_1.provider_performance = ProviderPerformance(1000 / 1.25)
mock_offer_1.provider_performance = ProviderPerformance(
1 * USAGE_SECOND / 1.25)
self.mock_offer_1 = mock_offer_1

mock_offer_2 = Mock()
mock_offer_2.provider_id = self.PROVIDER_2
mock_offer_2.quality = (.0, .0, .0, .0)
mock_offer_2.reputation = .0
mock_offer_2.price = 6.0
mock_offer_2.provider_performance = ProviderPerformance(1000 / 0.8)
mock_offer_2.provider_performance = ProviderPerformance(
1 * USAGE_SECOND / 0.8)
self.mock_offer_2 = mock_offer_2

def test_get_usage_benchmark(self):
self.assertEqual(
RequestorWasmMarketStrategy.get_my_usage_benchmark(), 1.0
RequestorWasmMarketStrategy.get_my_usage_benchmark(),
RequestorWasmMarketStrategy.DEFAULT_USAGE_BENCHMARK
)
self.assertEqual(
RequestorWasmMarketStrategy.get_usage_factor(self.PROVIDER_1, 1.0),
RequestorWasmMarketStrategy.get_usage_factor(
self.PROVIDER_1,
RequestorWasmMarketStrategy.DEFAULT_USAGE_BENCHMARK
),
1.0
)

Expand Down