diff --git a/golem/marketplace/wasm_marketplace.py b/golem/marketplace/wasm_marketplace.py index 23c3bb2fd4..437cea2929 100644 --- a/golem/marketplace/wasm_marketplace.py +++ b/golem/marketplace/wasm_marketplace.py @@ -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() @@ -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 @@ -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) + logger.info("RWMS: initial usage factor for %s = %.3f", + provider_id, + usage_factor) + cls._usage_factors[provider_id] = usage_factor return usage_factor diff --git a/tests/golem/marketplace/test_wasm_marketplace.py b/tests/golem/marketplace/test_wasm_marketplace.py index b2d34d9cd8..01940bd8bf 100644 --- a/tests/golem/marketplace/test_wasm_marketplace.py +++ b/tests/golem/marketplace/test_wasm_marketplace.py @@ -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' @@ -21,7 +23,8 @@ 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() @@ -29,15 +32,20 @@ def setUp(self): 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 )