forked from Tencent/Pebble
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0f32f94
Showing
601 changed files
with
156,837 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
开发环境搭建和使用说明: | ||
|
||
|
||
请确保机器已安装python 2.6以上版本。 | ||
|
||
一、编译 | ||
1、如何安装blade | ||
blade的内容已经放在目录tools/blade下 | ||
|
||
cd blade | ||
./install | ||
source ~/.bash_profile | ||
|
||
2、如何安装scons | ||
scons2.3.4的内容已经放在目录tools/scons下 | ||
|
||
cd scons | ||
tar xvf scons-2.3.4.tar.gz | ||
cd scons-2.3.4 | ||
python setup.py install | ||
|
||
blade依赖scons 2.0以上版本。如有其他需要,可以到下面地址下载: | ||
http://www.scons.org/download.php | ||
|
||
3、安装zmq | ||
到http://download.zeromq.org/下载zmq 4.05 | ||
解压后执行 | ||
./autogen.sh | ||
./configure | ||
make | ||
make install | ||
ldconfig | ||
|
||
4、安装jdk(如果已安装,可跳过): | ||
yum install java-1.6.0-openjdk.x86_64 | ||
|
||
5、编译所有内容 | ||
进入项目根目录 | ||
blade build ... | ||
注:blade是一个编译工具,其文档在:tools/blade/doc | ||
|
||
|
||
|
||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# 分布式开发框架Pebble使用说明 | ||
|
||
---------- | ||
##简介 | ||
Pebble是一个分布式开发框架。基于该框架,可以让开发者只需专注于业务逻辑的实现,而不需要关注基础功能的开发,如网络通信,数据存储,集群管理等。使用pebble配套的运营系统,可方便的进行游戏开区开服,版本升级,扩容缩容等操作。 | ||
|
||
当前发布的Pebble版本,是一个Linux平台C++版本的后台开发框架。整个分布式开发框架包括:服务管理、集群管理、RPC通信、协程、广播、进程框架。 | ||
|
||
- **服务管理**:有了服务管理功能,客户端无需手工配置服务器端的地址即可通信。每一个服务(service)都有一个唯一的名字,服务由一组具体的函数组成,每个服务器进程可以管理多个服务。我们使用[ZooKeeper](http://zookeeper.apache.org)来帮助完成服务和集群状态管理:使用Pebble框架,服务端可方便的将服务的地址注册到ZooKeeper,客户端根据服务名字可方便的从ZooKeeper获得服务器地址。 | ||
|
||
- **集群管理**:服务进程启动后,会自动与ZooKeeper之间维持心跳。客户端会定时从ZooKeeper获取服务器端的地址信息,一旦服务进程故障,客户端会自动将其从服务列表中去除。同理,增加服务进程也是一样。从而可方便的实现集群状态管理,可方便的对服务器进行扩容和缩容。 | ||
|
||
- **RPC通信**:RPC(Remote Procedure Call,远程过程调用),可以让开发者基于接口编程,更加专注于业务逻辑。借用于接口描述语言(IDL)和工具,可以自动生成客户端和服务器端的接口代码,服务器按需实现自己的业务逻辑,客户端只需要按接口调用。双方均无需要关心协议编解码、网络发送的细节,减轻了开发量的同时也减少出错的可能。 | ||
|
||
- **协程**:协程可降低异步代码的复杂度,让代码看起来像同步一样,同时具有异步的性能。开发框架很好的集成了协程的功能,服务器端的处理已经在一个协程里面。当服务器端收到客户端的RPC请求时,系统会自动为你创建协程,请注意不要调用阻塞操作。如果要调用阻塞操作,需要将其修改为以协程的方式调用,否则整个server的处理能力会受到影响。 | ||
|
||
- **广播**:广播是游戏业务的一个常见需求。pebble支持服务器端server之间的广播,也支持多服务器与多手机客户端之间的广播。无论是手机客户端还是后台服务器,只要大家加入一个相同的频道(channel),就可以做到一呼百应。广播功能是在RPC的基础上实现,所以它的编程体验与RPC是一致的。 | ||
|
||
- **进程框架**:它是一个单线程的开发框架,集成了上述功能。使用我们的框架,只需要调用少量接口,即可快速开发出游戏后台server。 | ||
|
||
|
||
----- | ||
Copyright ©1998 - 2015 Tencent. All Rights Reserved. | ||
|
||
腾讯公司 版权所有 | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# 常见问题 | ||
|
||
1. Pebble是什么? | ||
|
||
Pebble是一个专注游戏领域的开发框架,为游戏开发者提供接入、容灾、集群、RPC、协程等功能。 | ||
|
||
2. 在Pebble下用哪种语言进行开发? | ||
|
||
服务器端目前只支持C++,而客户端目前Unity下是C# SDK,cocos2d下是C++ SDK。 | ||
|
||
3. Pebble的并发模型是? | ||
|
||
基于协程的异步模型。 | ||
|
||
4. 监听地址和服务是否绑定? | ||
|
||
无绑定关系,也就是进程里每个服务都可以通过进程设置的监听地址提供服务。 | ||
|
||
5. HTTP是否支持长连接? | ||
|
||
作为服务提供方是支持的,服务请求方不支持。 | ||
|
||
6. 在服务处理函数中如何调用其他服务? | ||
|
||
你拿到一个RPC stub对象,就像使用本地对象一样使用服务,和在哪里用(包括服务处理函数中)没关系。 | ||
|
||
7. 支持哪几种路由策略? | ||
|
||
三种:轮询,哈希,取模。 | ||
|
||
8. 通过名字服务访问是否每次都要拉取地址? | ||
|
||
第一次访问会拉一次并cache,以后访问直接从cache获取,不需要到远端拉取。如果有更新会通过watch监听到并更新本地cache。 | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# HelloWorld | ||
|
||
---------- | ||
##环境搭建 | ||
1、下载Pebble | ||
首先,你得先到这里下载Pebble | ||
2、编译安装 | ||
根据这篇文档,完成Pebble的编译、安装 | ||
|
||
##例子 | ||
|
||
###通过IDL定义前后端交互接口 | ||
namespace cpp tutorial | ||
|
||
service Tutorial { | ||
string helloworld(1: string who) | ||
} | ||
|
||
###生成代码 | ||
####C++服务端 | ||
pebble -gen cpp helloworld.pebble | ||
####客户端(Unity) | ||
pebble -gen csharp helloworld.pebble | ||
|
||
###C++服务端 | ||
####服务实现 | ||
class TutorialHandler : public TutorialCobSvIf { | ||
public: | ||
void helloworld(const std::string& who, cxx::function<void(std::string const& _return)> cob) { | ||
std::cout << who << " say helloworld!" << std::endl; | ||
cob("Hello " + who + "!"); | ||
} | ||
}; | ||
####服务启动 | ||
// 初始化PebbleServer | ||
pebble::PebbleServer pebble_server; | ||
pebble_server.Init(argc, argv, "cfg/pebble.ini"); | ||
// 注册服务 | ||
TutorialHandler service; | ||
pebble_server.RegisterService(&service); | ||
// 添加服务监听地址 | ||
pebble_server.AddServiceManner("http://0.0.0.0:8300", pebble::rpc::PROTOCOL_BINARY); | ||
// 启动server | ||
pebble_server.Start(); | ||
|
||
|
||
###Unity客户端 | ||
####初始化 | ||
if (!HttpTransportCreator.Initial()) | ||
{ | ||
throw new Exception("Init HTTPTransportCreator fail!"); | ||
} | ||
|
||
Rpc.Instance.SetDefaultCommunicationParam("http://10.12.234.103:8300");//调用这个API设置默认的通讯参数 | ||
client = Rpc.Instance.GetClient<Tutorial.Client>();//可填通讯参数,不填时用SetDefaultCommunicationParam所设置的值 | ||
|
||
####每帧的Tick | ||
Rpc.Instance.Update(); | ||
|
||
####RPC调用 | ||
client.helloworld("John", (ex, result) => | ||
{ | ||
if (ex != null) | ||
{ | ||
Debug.Log("RPC BaseService.heartbeat exception: " + ex); | ||
} | ||
else | ||
{ | ||
Debug.Log("RPC BaseService.heartbeat return: " + result); | ||
} | ||
}); | ||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# make file for examples | ||
|
||
BASE_PATH = ../.. | ||
PEBBLE = $(BASE_PATH)/tools/pebble/pebble | ||
|
||
INC_PATH = $(BASE_PATH)/include | ||
|
||
LIB_PATH = $(BASE_PATH)/lib | ||
|
||
PEBBLE_IDL = broadcast_tutorial.pebble | ||
PEBBLE_SRC = idl/broadcast_tutorial.cpp idl/broadcast_tutorial_BroadcastTest.cpp idl/broadcast_tutorial_BroadcastTrigger.cpp | ||
PEBBLE_H = idl/broadcast_tutorial.h idl/broadcast_tutorial_BroadcastTest_if.h idl/broadcast_tutorial_BroadcastTrigger_if.h | ||
PEBBLE_OBJ = $(subst .cpp,.o, $(PEBBLE_SRC)) | ||
|
||
SERVER_SRC = broadcast_server.cpp | ||
SERVER_OBJ = $(subst .cpp,.o, $(SERVER_SRC)) | ||
SERVER = broadcast_server | ||
|
||
CLIENT_SRC = broadcast_client.cpp | ||
CLIENT_OBJ = $(subst .cpp,.o, $(CLIENT_SRC)) | ||
CLIENT = broadcast_client | ||
|
||
INC_FLAGS = -I$(BASE_PATH) -I$(INC_PATH) -I$(INC_PATH)/source | ||
|
||
LD_FLAGS = -L$(LIB_PATH)/app -L$(LIB_PATH)/rpc -L$(LIB_PATH)/message -L$(LIB_PATH)/service \ | ||
-L$(LIB_PATH)/oss -L$(LIB_PATH)/common -L$(LIB_PATH)/log \ | ||
-L$(LIB_PATH)/zookeeper -L$(LIB_PATH)/inih-master -L$(LIB_PATH)/zeromq \ | ||
-lpebble_app -lpebble_rpc_s -lpebble_message -lpebble_service_manage \ | ||
-lpebble_common -lpebble_log \ | ||
-lzookeeper_st -lanl -linih -lzmq -lrt -lpthread | ||
|
||
CC_FLAGS = -g -Wall -Werror $(INC_FLAGS) | ||
|
||
CC = g++ | ||
|
||
.PHONY: all clean | ||
|
||
all: $(SERVER) $(CLIENT) | ||
|
||
$(SERVER): $(PEBBLE_OBJ) $(SERVER_OBJ) | ||
$(CC) -o $@ $^ $(LD_FLAGS) | ||
|
||
$(CLIENT): $(PEBBLE_OBJ) $(CLIENT_OBJ) | ||
$(CC) -o $@ $^ $(LD_FLAGS) | ||
|
||
$(PEBBLE_SRC): $(PEBBLE_IDL) | ||
$(PEBBLE) -r -out ./idl --gen cpp $< | ||
|
||
%.o: %.cpp | ||
$(CC) -o $@ -c $< $(CC_FLAGS) | ||
|
||
clean: | ||
rm -f $(SERVER) $(CLIENT) ./*.o $(PEBBLE_SRC) $(PEBBLE_H) ./idl/*.o | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# make file for examples | ||
|
||
BASE_PATH = ../.. | ||
PEBBLE = $(BASE_PATH)/tools/pebble/pebble | ||
|
||
INC_PATH = $(BASE_PATH)/include | ||
|
||
LIB_PATH = $(BASE_PATH)/lib | ||
|
||
PEBBLE_IDL = broadcast_tutorial.pebble | ||
PEBBLE_SRC = idl/broadcast_tutorial.cpp idl/broadcast_tutorial_BroadcastTest.cpp idl/broadcast_tutorial_LoginService.cpp | ||
PEBBLE_H = idl/broadcast_tutorial.h idl/broadcast_tutorial_BroadcastTest_if.h idl/broadcast_tutorial_LoginService_if.h | ||
PEBBLE_OBJ = $(subst .cpp,.o, $(PEBBLE_SRC)) | ||
|
||
SERVER_SRC = broadcast_server.cpp | ||
SERVER_OBJ = $(subst .cpp,.o, $(SERVER_SRC)) | ||
SERVER = broadcast_server | ||
|
||
CLIENT_SRC = broadcast_client.cpp | ||
CLIENT_OBJ = $(subst .cpp,.o, $(CLIENT_SRC)) | ||
CLIENT = broadcast_client | ||
|
||
INC_FLAGS = -I$(BASE_PATH) -I$(INC_PATH) -I$(INC_PATH)/source | ||
|
||
LD_FLAGS = -L$(LIB_PATH)/app -L$(LIB_PATH)/rpc -L$(LIB_PATH)/message -L$(LIB_PATH)/service \ | ||
-L$(LIB_PATH)/oss -L$(LIB_PATH)/common -L$(LIB_PATH)/log \ | ||
-L$(LIB_PATH)/zookeeper -L$(LIB_PATH)/inih-master -L$(LIB_PATH)/zeromq \ | ||
-lpebble_app -lpebble_rpc_s -lpebble_message -lpebble_service_manage \ | ||
-lpebble_common -lpebble_log \ | ||
-lzookeeper_st -lanl -linih -lzmq -lrt -lpthread | ||
|
||
CC_FLAGS = -g -Wall -Werror $(INC_FLAGS) | ||
|
||
CC = g++ | ||
|
||
.PHONY: all clean | ||
|
||
all: $(SERVER) $(CLIENT) | ||
|
||
$(SERVER): $(PEBBLE_OBJ) $(SERVER_OBJ) | ||
$(CC) -o $@ $^ $(LD_FLAGS) | ||
|
||
$(CLIENT): $(PEBBLE_OBJ) $(CLIENT_OBJ) | ||
$(CC) -o $@ $^ $(LD_FLAGS) | ||
|
||
$(PEBBLE_SRC): $(PEBBLE_IDL) | ||
$(PEBBLE) -r -out ./idl --gen cpp $< | ||
|
||
%.o: %.cpp | ||
$(CC) -o $@ -c $< $(CC_FLAGS) | ||
|
||
clean: | ||
rm -f $(SERVER) $(CLIENT) ./*.o $(PEBBLE_SRC) $(PEBBLE_H) ./idl/*.o | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# make file for examples | ||
|
||
BASE_PATH = ../.. | ||
|
||
INC_PATH = $(BASE_PATH)/include | ||
|
||
LIB_PATH = $(BASE_PATH)/lib | ||
|
||
EXAMPLE_SRC = coroutine_tutorial.cpp | ||
EXAMPLE_OBJ = $(subst .cpp,.o, $(EXAMPLE_SRC)) | ||
EXAMPLE = coroutine_tutorial | ||
|
||
INC_FLAGS = -I$(INC_PATH) | ||
|
||
LD_FLAGS = -L$(LIB_PATH)/common -L$(LIB_PATH)/log -lpebble_common -lpebble_log -lpthread | ||
|
||
CC_FLAGS = -g -Wall -Werror $(INC_FLAGS) | ||
|
||
CC = g++ | ||
|
||
.PHONY: all clean | ||
|
||
all: $(EXAMPLE) | ||
|
||
$(EXAMPLE): $(EXAMPLE_OBJ) | ||
$(CC) -o $@ $^ $(LD_FLAGS) | ||
|
||
%.o: %.cpp | ||
$(CC) -o $@ -c $< $(CC_FLAGS) | ||
|
||
clean: | ||
rm -f $(EXAMPLE) ./*.o | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# make file for examples | ||
|
||
BASE_PATH = ../.. | ||
|
||
INC_PATH = $(BASE_PATH)/include | ||
|
||
LIB_PATH = $(BASE_PATH)/lib | ||
|
||
SERVER_SRC = message_server.cpp | ||
SERVER_OBJ = $(subst .cpp,.o, $(SERVER_SRC)) | ||
SERVER = message_server | ||
|
||
CLIENT_SRC = message_client.cpp | ||
CLIENT_OBJ = $(subst .cpp,.o, $(CLIENT_SRC)) | ||
CLIENT = message_client | ||
|
||
INC_FLAGS = -I$(INC_PATH) -I$(INC_PATH)/source/message | ||
|
||
LD_FLAGS = -L$(LIB_PATH)/message -L$(LIB_PATH)/rpc \ | ||
-L$(LIB_PATH)/common -L$(LIB_PATH)/zookeeper -L$(LIB_PATH)/zeromq \ | ||
-lpebble_message -lpebble_rpc_s -lpebble_common \ | ||
-lzookeeper_st -lzmq -lrt -lpthread | ||
|
||
CC_FLAGS = -g -Wall -Werror $(INC_FLAGS) | ||
|
||
CC = g++ | ||
|
||
.PHONY: all clean | ||
|
||
all: $(SERVER) $(CLIENT) | ||
|
||
$(SERVER): $(SERVER_OBJ) | ||
$(CC) -o $@ $^ $(LD_FLAGS) | ||
|
||
$(CLIENT): $(CLIENT_OBJ) | ||
$(CC) -o $@ $^ $(LD_FLAGS) | ||
|
||
%.o: %.cpp | ||
$(CC) -o $@ -c $< $(CC_FLAGS) | ||
|
||
clean: | ||
rm -f $(SERVER) $(CLIENT) ./*.o | ||
|
Oops, something went wrong.