Skip to content

Commit

Permalink
Merge branch 'master' into bazel-build
Browse files Browse the repository at this point in the history
  • Loading branch information
cyshi committed Jan 17, 2017
2 parents d3ede4d + b29cd42 commit bc4a1bb
Show file tree
Hide file tree
Showing 12 changed files with 883 additions and 114 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,12 @@ else
endif
endif

ifndef CXX
CXX=g++
endif

#-----------------------------------------------

CXX=g++
INCPATH=-Isrc -I$(BOOST_HEADER_DIR) -I$(PROTOBUF_DIR)/include -I$(SNAPPY_DIR)/include -I$(ZLIB_DIR)/include
CXXFLAGS += $(OPT) -pipe -W -Wall -fPIC -D_GNU_SOURCE -D__STDC_LIMIT_MACROS -DHAVE_SNAPPY $(INCPATH)

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ For more details, please refer to the wiki [Build Guide](https://github.com/baid
### Sample
For sample code, please refer to ['./sample'](https://github.com/baidu/sofa-pbrpc/tree/master/sample) and the wiki [Quick Start](https://github.com/baidu/sofa-pbrpc/wiki/%E5%BF%AB%E9%80%9F%E4%BD%BF%E7%94%A8).

### Profiling
For Profiling feature, please refer to the wiki [Profiling](https://github.com/baidu/sofa-pbrpc/wiki/Profiling%E5%8A%9F%E8%83%BD).

### Performance
For performace details, please refer to the wiki [Performance](https://github.com/baidu/sofa-pbrpc/wiki/%E6%80%A7%E8%83%BD).

Expand Down
65 changes: 65 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env bash
set -x -e

########################################
# download & build depend software
########################################

DEPS_PREFIX=`pwd`/thirdparty
DEPS_CONFIG="--prefix=${DEPS_PREFIX} --disable-shared --with-pic"
FLAG_DIR=`pwd`/.build

export PATH=${DEPS_PREFIX}/bin:$PATH
mkdir -p ${DEPS_PREFIX} ${FLAG_DIR}

# boost
if [ ! -f "${FLAG_DIR}/boost_1_57_0" ] \
|| [ ! -d "${DEPS_PREFIX}/boost_1_57_0/boost" ]; then
wget -O ${DEPS_PREFIX}/boost_1_57_0.tar.gz http://sourceforge.net/projects/boost/files/boost/1.57.0/boost_1_57_0.tar.gz
tar zxf ${DEPS_PREFIX}/boost_1_57_0.tar.gz -C ${DEPS_PREFIX}
touch "${FLAG_DIR}/boost_1_57_0"
fi

# protobuf
if [ ! -f "${FLAG_DIR}/protobuf_2_6_1" ] \
|| [ ! -f "${DEPS_PREFIX}/lib/libprotobuf.a" ] \
|| [ ! -d "${DEPS_PREFIX}/include/google/protobuf" ]; then
wget -O ${DEPS_PREFIX}/protobuf-2.6.1.tar.gz https://github.com/google/protobuf/releases/download/v2.6.1/protobuf-2.6.1.tar.gz
tar zxf ${DEPS_PREFIX}/protobuf-2.6.1.tar.gz -C ${DEPS_PREFIX}
cd ${DEPS_PREFIX}/protobuf-2.6.1
autoreconf -ivf
./configure ${DEPS_CONFIG}
make -j4
make install
cd -
touch "${FLAG_DIR}/protobuf_2_6_1"
fi

# snappy
if [ ! -f "${FLAG_DIR}/snappy_1_1_1" ] \
|| [ ! -f "${DEPS_PREFIX}/lib/libsnappy.a" ] \
|| [ ! -f "${DEPS_PREFIX}/include/snappy.h" ]; then
wget -O ${DEPS_PREFIX}/snappy-1.1.3.tar.gz https://github.com/google/snappy/releases/download/1.1.3/snappy-1.1.3.tar.gz
tar zxf ${DEPS_PREFIX}/snappy-1.1.3.tar.gz -C ${DEPS_PREFIX}
cd ${DEPS_PREFIX}/snappy-1.1.3
./configure ${DEPS_CONFIG}
make -j4
make install
cd -
touch "${FLAG_DIR}/snappy_1_1_1"
fi

########################################
# config depengs.mk
########################################

echo "BOOST_HEADER_DIR="${DEPS_PREFIX}"/boost_1_57_0" > depends.mk
echo "PROTOBUF_DIR="${DEPS_PREFIX} >> depends.mk
echo "SNAPPY_DIR="${DEPS_PREFIX} >> depends.mk

########################################
# install sofa-pbrpc
########################################

make clean
make -j4 && make install
Binary file added image/sofa-pbrpc-cpu-profiling.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/sofa-pbrpc-memory-profiling.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 21 additions & 3 deletions src/sofa/pbrpc/binary_rpc_request_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
namespace sofa {
namespace pbrpc {

#define SOFA_PBRPC_MAX_RPC_MESSAGE_SIZE (64 << 20)
const int64 BinaryRpcRequestParser::MAX_MESSAGE_SIZE =
SOFA_PBRPC_MAX_RPC_MESSAGE_SIZE + sizeof(RpcMessageHeader);

BinaryRpcRequestParser::BinaryRpcRequestParser() :
_state(PS_MAGIC_STRING),
_bytes_recved(0),
Expand Down Expand Up @@ -51,12 +55,12 @@ int BinaryRpcRequestParser::Parse(const char* buf,
return 0;
}
*bytes_consumed = 0;
int bytes_remain, consume;
int64 bytes_remain, consume;
switch (_state)
{
case PS_MSG_HEADER:
bytes_remain = sizeof(RpcMessageHeader) - _bytes_recved;
consume = std::min(data_size, bytes_remain);
consume = std::min(static_cast<int64>(data_size), bytes_remain);
memcpy(reinterpret_cast<char*>(&_req->_req_header) + _bytes_recved,
buf + offset, consume);
*bytes_consumed += consume;
Expand All @@ -82,7 +86,21 @@ int BinaryRpcRequestParser::Parse(const char* buf,
}
case PS_MSG_BODY:
bytes_remain = _req->_req_header.message_size - _bytes_recved;
consume = std::min(data_size, bytes_remain);
if (bytes_remain > MAX_MESSAGE_SIZE || bytes_remain <= 0)
{
// compute bytes_remain error
#if defined( LOG )
LOG(ERROR) << "Parse(): " << RpcEndpointToString(_req->_remote_endpoint)
<< ": compute bytes_remain[" << bytes_remain
<< "] error, message size limit[" << MAX_MESSAGE_SIZE << "]";
#else
SLOG(ERROR, "Parse(): %s: compute bytes_remain[%lld] error, message size limit[%lld]",
RpcEndpointToString(_req->_remote_endpoint).c_str(),
bytes_remain, MAX_MESSAGE_SIZE);
#endif
return -1;
}
consume = std::min(static_cast<int64>(data_size), bytes_remain);
_req->_req_body->Append(BufHandle(const_cast<char*>(buf), consume, offset));
*bytes_consumed += consume;
_bytes_recved += consume;
Expand Down
2 changes: 2 additions & 0 deletions src/sofa/pbrpc/binary_rpc_request_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class BinaryRpcRequestParser : public RpcRequestParser
ParseState _state; // current parsing state
int _bytes_recved; // bytes received in current state
BinaryRpcRequestPtr _req;

static const int64 MAX_MESSAGE_SIZE;
}; // class BinaryRpcRequestParser

} // namespace pbrpc
Expand Down
Loading

0 comments on commit bc4a1bb

Please sign in to comment.