-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Quick start guide
Pomelo is a high-performance and distributed framework for node.js. It can help you avoid boring repeat manual labour and underlying logic with some simple commands. Please run pomelo under linux or mac os for it runing under windows with not tested.
Install pomelo by npm(node package manager):
npm install pomelo -g
Also you can install with source from git through the commands
git clone https://github.com/NetEase/pomelo.git
cd pomelo
npm install -g
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. At last, the dependencies should be installed by command "sh npm-install.sh" (linux) or npm install -d (windows)
A new project is made up of many folders as follows:
The directory structure corresponds to the game logic, and you can fill code in related directory.
More information about this directory:
Game-server made of pomelo contains all of the game logic and components. In practical work, all codes about game logic and components should be fill here.
Generally, a project needs a lot of configurations and you can finish them by JSON files here. In game project, some configurations have been created such as log, master-server and other servers at initialization. Also, you can add database, map and numerical tabular configuration etc.
Logs are essential for the project and contain a number of informations which you can get the project running state from.
Both some configurations and code resources can be shared between client and server if you choose javascript to run client.
Web server made of express receives requests from players. Beside express, you can choose other web server like nginx.
Both game-server and web-server should be started, and game-server can be started by command
pomelo start [development | production] [--daemon]
while web-server is
cd web-server && node app
Running in different environment, the project needs different start arguments. If the running environment is development, argument is development, while production environment is production. By default the project runs in the foreground, and the argument '--daemon' can let project run in the background.
Running in daemon, 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 with command pomelo list
, and the result is shown as follows:
The result shows server state as follows:
- serverId: the id of server which is same with configuration
- serverType: the type of server which is same with 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
Both command pomelo stop
and pomelo kill
can shutdown the project. The command pomelo stop
is recommended for some
reasons as follows:
- front-end server 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 is a power tool which can monitor the project and get valuable information. You can do many things with adminConsole.
- Monitor server status, logs, online users and scene data etc.
- Get related information by script flexibly.
- Trace and analyze memory stack, CPU consumption
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'.
If multi-server, not only all the servers should support 'ssh agent forward' but also the project directory structure of each server is exactly the same in production,
Some references about 'ssh agent forward':