Beispiel #1
0
 def __exec(self, method, params=None):
     """Perform a single steemd call."""
     start = perf()
     result = self._client.exec(method, params)
     items = len(params[0]) if method == 'get_accounts' else 1
     Stats.log_steem(method, perf() - start, items)
     return result
Beispiel #2
0
    def __exec(self, method, params=None):
        """Perform a single dpayd call."""
        time_start = time.perf_counter()
        result = self._client.exec(method, params)
        total_time = (time.perf_counter() - time_start) * 1000

        batch_size = len(params[0]) if method == 'get_accounts' else 1
        Stats.log_dpay(method, total_time, batch_size)
        return result
Beispiel #3
0
    def __exec_batch(self, method, params):
        """Perform batch call. Based on config uses either batch or futures."""
        start = perf()

        result = []
        for part in self._client.exec_multi(method,
                                            params,
                                            max_workers=self._max_workers,
                                            batch_size=self._max_batch):
            result.extend(part)

        Stats.log_steem(method, perf() - start, len(params))
        return result
Beispiel #4
0
    def __exec_batch(self, method, params):
        """Perform batch call. Based on config uses either batch or futures."""
        time_start = time.perf_counter()

        result = []
        for part in self._client.exec_multi(method,
                                            params,
                                            max_workers=self._max_workers,
                                            batch_size=self._max_batch):
            result.extend(part)

        total_time = (time.perf_counter() - time_start) * 1000
        Stats.log_dpay(method, total_time, len(params))
        return result
Beispiel #5
0
    def _query(self, sql, **kwargs):
        """Send a query off to SQLAlchemy."""
        if sql == 'START TRANSACTION':
            assert not self._trx_active
            self._trx_active = True
        elif sql == 'COMMIT':
            assert self._trx_active
            self._trx_active = False

        try:
            start = perf()
            query = self._sql_text(sql)
            result = self._exec(query, **kwargs)
            Stats.log_db(sql, perf() - start)
            return result
        except Exception as e:
            log.info("[SQL-ERR] %s in query %s (%s)", e.__class__.__name__,
                     sql, kwargs)
            raise e
Beispiel #6
0
    def wait_for_block(self, num):
        """Sleep until the requested block is expected to be available.

        Returns current head block (which is always gte `num`)"""
        head_time = time() - self._drift

        # if slots missed, advance head block
        while head_time >= self._next_expected:
            self._advance()
            if head_time < self._next_expected:
                log.warning("%d blocks behind", self._head_num - num)

        # if head is behind, sleep until ready
        while self._head_num < num:
            wait_secs = self._next_expected - head_time
            sleep(wait_secs)
            Stats.log_idle(wait_secs)
            head_time = self._next_expected
            self._advance()

        return self._head_num
Beispiel #7
0
    def _query(self, sql, is_prepared, **kwargs):
        """Send a query off to SQLAlchemy."""
        if sql == 'START TRANSACTION':
            assert not self._trx_active
            self._trx_active = True
        elif sql == 'COMMIT':
            assert self._trx_active
            self._trx_active = False

        try:
            start = perf()
            query = self._sql_text(sql, is_prepared)
            if 'log_query' in kwargs and kwargs['log_query']:
                log.info("QUERY: {}".format(query))
            result = self._basic_connection.execution_options(autocommit=False).execute(query, **kwargs)
            if 'log_result' in kwargs and kwargs['log_result']:
                log.info("RESULT: {}".format(result))
            Stats.log_db(sql, perf() - start)
            return result
        except Exception as e:
            log.warning("[SQL-ERR] %s in query %s (%s)",
                        e.__class__.__name__, sql, kwargs)
            raise e
Beispiel #8
0
 async def _wrapper(*args, **kwargs):
     start = perf()
     result = await function(*args, **kwargs)
     Stats.log_db(args[1], perf() - start)
     return result