Exemple #1
0
    def __init__(self, host=None, port=None, db=None):
        """Initialize a new RethinkDB Backend instance.

        Args:
            host (str): the host to connect to.
            port (int): the port to connect to.
            db (str): the name of the database to use.
        """

        self.read_mode = 'majority'
        self.durability = 'soft'
        self.connection = Connection(host=host, port=port, db=db)
Exemple #2
0
    def __init__(self,
                 host=None,
                 port=None,
                 dbname=None,
                 backend=None,
                 public_key=None,
                 private_key=None,
                 keyring=[],
                 backlog_reassign_delay=None):
        """Initialize the Bigchain instance

        A Bigchain instance has several configuration parameters (e.g. host).
        If a parameter value is passed as an argument to the Bigchain
        __init__ method, then that is the value it will have.
        Otherwise, the parameter value will come from an environment variable.
        If that environment variable isn't set, then the value
        will come from the local configuration file. And if that variable
        isn't in the local configuration file, then the parameter will have
        its default value (defined in bigchaindb.__init__).

        Args:
            host (str): hostname where RethinkDB is running.
            port (int): port in which RethinkDB is running (usually 28015).
            dbname (str): the name of the database to connect to (usually bigchain).
            backend (:class:`~bigchaindb.db.backends.rethinkdb.RehinkDBBackend`):
                the database backend to use.
            public_key (str): the base58 encoded public key for the ED25519 curve.
            private_key (str): the base58 encoded private key for the ED25519 curve.
            keyring (list[str]): list of base58 encoded public keys of the federation nodes.
        """

        config_utils.autoconfigure()
        self.host = host or bigchaindb.config['database']['host']
        self.port = port or bigchaindb.config['database']['port']
        self.dbname = dbname or bigchaindb.config['database']['name']
        self.backend = backend or get_backend(host, port, dbname)
        self.me = public_key or bigchaindb.config['keypair']['public']
        self.me_private = private_key or bigchaindb.config['keypair']['private']
        self.nodes_except_me = keyring or bigchaindb.config['keyring']
        self.backlog_reassign_delay = backlog_reassign_delay or bigchaindb.config[
            'backlog_reassign_delay']
        self.consensus = BaseConsensusRules
        # change RethinkDB read mode to majority.  This ensures consistency in query results
        self.read_mode = 'majority'

        if not self.me or not self.me_private:
            raise exceptions.KeypairNotFoundException()

        self.connection = Connection(host=self.host,
                                     port=self.port,
                                     db=self.dbname)
Exemple #3
0
import time

import rethinkdb as r

from bigchaindb import Bigchain
from bigchaindb.db.utils import Connection


def update_flag_limit(limit=1000):
    import random
    return connection.run(
        r.table('backlog').limit(limit).update(
            {'assignee_isdeal': random.random()}, return_changes=True))


times = 2000
b = Bigchain()
start = time.time()
connection = Connection()
result = update_flag_limit(times)
end = time.time()
print("end", end)
print("takes", end - start, "seconds")
print("update tx", times / (end - start), "times/s")
print("len of changes", len(result['changes']))