Skip to content

Commit

Permalink
Updated instructions and dockerfile for testing with tm-bench
Browse files Browse the repository at this point in the history
  • Loading branch information
30mb1 committed Oct 1, 2018
1 parent bfd216f commit 71ed375
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 11 deletions.
9 changes: 9 additions & 0 deletions Dockerfile2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM python:3.6

ENV TENDERMINT_PORT 26657

RUN mkdir -p /app
COPY . /app/
WORKDIR /app

RUN pip install --no-cache-dir -e .
9 changes: 9 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ Or using Docker container:
3. Run container: ``sudo docker run -it abcidev sh``
4. Inside container run: ``make gogo``

Testing with tm-bench
---------------------
Use this if you want to test throughput of server and application. By default, dummpy app is used,
you can change it in docker-compose.yml, abci command section (before build).

1. Build tm-bench and move to tm-abci directory (you can get it `here <https://github.com/tendermint/tendermint/tree/master/tools/tm-bench>`_)
2. Change testing config in tm-bench command section of docker-compose.yml
3. Run ``sudo docker-compose -f docker-compose.yml up -d``
4. Wait about minute (or more/less if you changed default) and run ``sudo docker-compose -f docker-compose.yml logs --tail 50 tm-bench``

Getting Started
---------------
Expand Down
16 changes: 5 additions & 11 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,30 @@ services:
abci:
build:
context: .
dockerfile: Dockerfile2
image: tm-abci_abci
volumes:
- /home/user_name/projects/tm-abci:/app
environment:
TENDERMINT_HOST: tendermint
TENDERMINT_PORT: 26657
expose:
- "26658"

command: bash -c "pip install -e . && python examples/counter.py"
command: bash -c "python examples/test_app.py"

tendermint:
depends_on:
- abci
image: tendermint/tendermint:0.24.0
volumes:
- /home/user_name/tendermint:/tendermint
entrypoint: ''
command: tendermint node --proxy_app=abci:26658
command: sh -c "tendermint init && tendermint node --proxy_app=abci:26658"
expose:
- "26657"

tm-bench:
build:
context: .
dockerfile: Dockerfile
dockerfile: Dockerfile2
image: tm-abci_abci
volumes:
- /home/user_name/projects/tm-abci:/app
depends_on:
- tendermint
- abci
command: bash -c "./tm-bench -T 60 -r 2000 -c 5 -test.count 5 tendermint:26657"
command: bash -c "sleep 5 && ./tm-bench -T 60 -r 2000 -c 5 -test.count 5 tendermint:26657"
94 changes: 94 additions & 0 deletions examples/test_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
"""
Simple counting app. It only excepts values sent to it in order. The
state maintains the current count. For example if starting at state 0, sending:
-> 0x01 = ok
-> 0x03 = fail (expects 2)
To run it:
- make a clean new directory for tendermint
- start this server: python counter.py
- start tendermint: tendermint --home "YOUR DIR HERE" node
- The send transactions to the app:
curl http://localhost:46657/broadcast_tx_commit?tx=0x01
curl http://localhost:46657/broadcast_tx_commit?tx=0x02
...
to see the latest count:
curl http://localhost:46657/abci_query
The way the app state is structured, you can also see the current state value
in the tendermint console output.
"""
import struct
import abci.utils as util

from abci import (
ABCIServer,
BaseApplication,
ResponseInfo,
ResponseInitChain,
ResponseCheckTx, ResponseDeliverTx,
ResponseQuery,
ResponseCommit,
CodeTypeOk,
)

# Tx encoding/decoding
def encode_number(value):
return struct.pack('>I', value)

def decode_number(raw):
return int.from_bytes(raw, byteorder='big')

class SimpleCounter(BaseApplication):

def info(self, req) -> ResponseInfo:
"""
Since this will always respond with height=0, Tendermint
will resync this app from the begining
"""
r = ResponseInfo()
r.version = "1.0"
r.last_block_height = 0
r.last_block_app_hash = b''
return r

def init_chain(self, req) -> ResponseInitChain:
"""Set initial state on first run"""
self.txCount = 0
self.last_block_height = 0
return ResponseInitChain()

def check_tx(self, tx) -> ResponseCheckTx:
"""
Validate the Tx before entry into the mempool
Checks the txs are submitted in order 1,2,3...
If not an order, a non-zero code is returned and the tx
will be dropped.
"""
value = decode_number(tx)
# if not value == (self.txCount + 1):
# # respond with non-zero code
# return ResponseCheckTx(code=1)
return ResponseCheckTx(code=CodeTypeOk)

def deliver_tx(self, tx) -> ResponseDeliverTx:
"""Simply increment the state"""
self.txCount += 1
return ResponseDeliverTx(code=CodeTypeOk)

def query(self, req) -> ResponseQuery:
"""Return the last tx count"""
v = encode_number(self.txCount)
return ResponseQuery(code=CodeTypeOk, value=v, height=self.last_block_height)

def commit(self) -> ResponseCommit:
"""Return the current encode state value to tendermint"""
hash = struct.pack('>Q', self.txCount)
return ResponseCommit(data=hash)


if __name__ == '__main__':
# Create the app
app = ABCIServer(app=SimpleCounter())
# Run it
app.run()

0 comments on commit 71ed375

Please sign in to comment.