Skip to content
This repository has been archived by the owner on Sep 25, 2023. It is now read-only.

Quick start guide

halfblood369 edited this page Nov 7, 2012 · 60 revisions

Pomelo is a high-performance and distributed game server framework for node.js. Some commands can help you simplify the development process. All these commands are thoroughly tested on linux and mac os, but not on windows yet.

Installation

Install pomelo globally using npm(node package manager):

npm install pomelo -g

You can also download the source with following command:

git clone https://github.com/NetEase/pomelo.git

Usage

Create a new project

Both the command "pomelo init ./helloWorld" and "mkdir helloWorld && cd helloWorld && pomelo init ." can create a new project. The first one will automatically create directory and init it. Then, you can install dependencies with the following command: 'sh npm-install.sh'.

A new project is made up of the following folders :

directory structure

The directory structure clearly classify the game logic, all you should do is filling code in related directory.

The following are details of the directory:

game-server

Game-server is the folder contains all of the game logic and components. All the game server logics live here.

config

Generally, a project needs some configuration files, which we use in JSON format. The game server project contains configuration including master, servers, databases, logs etc.

logs

Logs are essential for the project and contain some information which you can get the project running state from.

shared

Both some configurations and codes can be shared between client and server if you choose javascript as client.

web-server

Web server contains web page and game client logic, which is based on express . It is quite suitable for web based game client, if you choose other client(unity 3d for example), you can totally ignore this folder.

Start project

Both game-server and web-server should be started, and game-server can be started by the following command

pomelo start [development | production] [--daemon]

while web-server is started like this: cd web-server && node app

Running in different environment, the project needs different start arguments. If the running environment is development, the argument should be development, otherwise it should be production. By default the project runs in foreground model, and the argument '--daemon' can let project run in background model.

If you use –daemon argument, the module 'forever' should be installed by command npm install forever -g

After project started, you can visit website of 'http://localhost:3001' or 'http://127.0.0.1:3001' by browser with websocket support.

Query server status

You can query server status with command pomelo list, and the example of result is shown as follows:

test

The followings are detail definition of each fields:

  • serverId: the id of server which is the same as configuration
  • serverType: the type of server which is the same as configuration
  • pid: the pid of process corresponding to server
  • cpuAvg: the CPU utilization rate of server
  • memAvg: the memory utilization rate of server
  • time: the start time of this server

Shutdown project

Both command pomelo stop and pomelo kill can shutdown the project. The command pomelo stop is recommended for some reasons as follows:

  • front-end servers disconnect to keep players from coming in
  • Guarantee game logic with closing all of the servers by certain order
  • Ensure data integrity with writing plays' information to the database in time

Please avoid the way with command pomelo kill in production environment for it killing process without any remedies.

AdminConsole

AdminConsole is a powerful tool which can monitor the project and get valuable information. You can do the following things with adminConsole.

  • Monitor server status, logs, online users and scene data etc.
  • Get related information with scripts flexibly.
  • Trace and analyze memory stack, CPU consumption

Install adminConsole

git clone https://github.com/NetEase/pomelo-admin-web.github

cd pomelo-admin-web

npm install -d

node app

Open the console by visiting website of 'http://localhost:7001' with browser which supports websocket. If any port conflicts, please fix configuration in 'config/admin.json'.

Project in production environment

If multi-server environment, not only all the servers should support "ssh agent forward" but also the project directory structure of each server should be exactly the same.

Here are some references about 'ssh agent forward':

Clone this wiki locally