Application of python in webgame

Source: Internet
Author: User
Tags virtualenv
Lai Yonghao (http://laiyonghao.com)
In early December 2011, the first pycon China conference was held in Shanghai. I was invited to give a report entitled "Application of python in webgame, the main idea has a complete description in the article (http://www.infoq.com/cn/articles/pycon-2011-first-in-china) written by infoq reporter Mr. Ding Xuefeng, I directly quoted here:
...... According to the application of python to webgame introduced by Rayong Hao, he first recommended two speeches he liked, one of which was Hong qiening's application of python on the Web 2.0 website. the other is Shen Yan's "Python programming art". Both of them are just the Speakers of the first day of the Conference. In his speech, Li Yonghao introduced the technology and some tools of the webgame server.
In terms of the library, he suggested that the library should be separated from the business logic, and Lib should be placed in site-packages; Do not manually configure the script setup. PY, which is generated using tools whenever possible. pastescript provides many functions such as creation, installation, testing, deployment, and running. You can use pbp. skels is used to generate a large number of codes, such as generating a namespace package. during deployment, there must be a pure Python environment, and virtualenv can be used.
In terms of plug-ins, we mainly use setuptools. For card and board games, game plug-ins can be divided into two parts: interface and implementation. Interfaces mainly include room process interaction and common functions (such as kicking people), timer management, interface definition, implementation is mainly to implement interfaces, business logic, the implementation part can not touch network programming, do not touch the database. If you are interested in plug-ins, you can also learn about TRAC component architecture.
Games and I/O are closely related. The author of node. js said:
I/O needs to be done differently.

He also agrees with this view, but does not quite agree with node. JS implementation method, node. JS has changed too much. He thinks the interface should be the same as before, but the underlying implementation method should be consistent with node. JS is similar. Currently, coroutine will become a trend. You can consider using gevent, which provides a set of Apis over libevent through greenlet. You can also refer to Shen Peng's Eurasia.
In other aspects, he discussed the use of binary protocols during communication. For example, Google's protobuf developed a program named Abu. the RPC communication framework uses protobuf, libevent, and greenlet, so it can implement smaller data volumes, faster transmission and synchronization APIs, and support parallel pipelines and bidirectional calling features. Inspired by the falcon language (an open-source Multi-paradigm language), the python-message language is developed to implement in-process publishing and subscription and is applied to subsystems such as tasks, emails, and friends. In addition, some small components, such as absolute32, are made to encapsulate some standard libraries. Currently, the pure Python game server he developed has a single 8-core 8 GB memory and can withstand a maximum of 1500 concurrent online users.

In January 2012, the Pearl River Delta technology Salon (http://techparty.org/) Guangzhou station, I once again fired this pot of cold rice, but because of the more time, the same slides I spoke twice the time, I spoke in Shanghai for 45 minutes, while in Guangzhou for a 91-minute version. This salon also has a video, so I think it is worth recording it on my blog and giving it to more people to watch, explore, and communicate. The addresses of the two reports are as follows:
Magic lamp: http://www.slideshare.net/laiyonghao/python-webgame-10452102
Video (Shanghai 45-minute edition): http://e.gensee.com/v_3df867_14
Video (91-minute Guangzhou edition): http://v.youku.com/v_playlist/f16785412o1p4.html
======================================
The following content is the slide text, which is purely used to attract traffic through search engines. Please ignore it.
--------------------------------
Application of python in webgame-presentation transcript
1. Application of python in Web-game Lai Yong Hao (http://laiyonghao.com) 2011.12.04 1
2. self-introduction • more than 6 years of online gaming experience • world-wide prosperity • once in NetEase, Jiangsu festival-team building-project management (Guangzhou) other companies-server side • Pearl River Delta technology salon-communication and security • Rayong Hao's private Programming Board • pihun-PV 1,000,000 +-server side-csdn blog top100-ai • Twitter /Weibo/42qu/CP • fantasy Three Kingdoms, Crazy Stone YUG/gzlug and bubble Game 2
3. Inspired ...... Http://slidesha.re/aGrXfY http://slidesha.re/fQhtkL 3
4. Based on my project, I will introduce the web-game server technology and tools from the project, which is higher than the project. 4
5. Project Introduction 1 • global prosperity-horizontal scroll-category web games • 0505u.com • full use of python for server development • 2010.08 ~ Now 5
6. Project Introduction 2 • board game onweb-qqgame copy cat • http://qp-demo.laiyonghao.com/client/• the server is fully developed using Python • 2009.01 ~ 2009.03 6
7. Library 7
8. Position of python in the python Project C/C ++ Python Lua C/C ++ Lua Python 8
9. Large and medium-sized Python project 9
10. Large and medium-sized Python Projects 10
11. Large and medium-sized Python projects 11
12. Lib should be in the LIB/Site-packages directory 12
13. Is it so complicated? 13
14. Just setup. py ...... • Avoid handwriting setup. py • How to Create a namespace package 14
15. artifacts Paster • http://pypi.python.org/pypi/pastescript • Create, install, test, deploy, run • wide different kinds of projects have created skeletons for their projects (pylons, turbogears, zopeskel, and others ). • http://pypi.python.org/pypi/pastedeploy 15
16. Basic usage 16
17. pbp. skels • http://pypi.python.org/pypi/pbp.skels• pbp. skels is a collection of templates to speed up the creation of standardized, boiler-plate code. 17
18. • Paster create-T pbp_package my. Package 18
19. http://lucasmanual.com/mywiki/PythonPaste write your own templates, commands 19
20. development, testing, packaging, and updating • Python setup. PY develop • Python setup. PY test • Python setup. PY bdist • Python setup. PY sdist -- formats = gztar, zip • Python setup. PY register • Python setup. PY upload 20
21. virtualenv • http://pypi.python.org/pypi/virtualenv• virtual Python environment builder • Application of python on Web 2.0 website
22. plugin 22
23. What is the difference between plugin and library? • A plugin extends the capabilities of a larger application. • A library is a collection of subroutines or classes used to develop software. • http://stackoverflow.com/a/2792342 23
24. Take chess and card on web as an example ...... 24
25. Go to the background and check out ...... 25
26. setuptools 26
27. setup. pyentry_points = "" #-*-entry points:-*-[qipaionweb. Games] doudizhu = doudizhu. game_impl: gameimpl "27
28. Def get_game_impl_class (game_name): Group = qipaionweb. Games prj = game_name return pkg_resources.load_entry_point (prj, group, game_name) 28
29. interface and implementation • game_interface • game_impl-interaction with room processes-implementation interface-general functions (kicker) -Implement business logic-timer management-No network access-define interfaces-no database access-single thread 29
30. Advanced: TRAC component architecture • TRAC. Core. componentmanager • TRAC. Core. Component • TRAC. Core. extensionpoint • TRAC. Core. Interface http://trac.edgewall.org/wiki/TracDev/ComponentArchitecture http://trac.edgewall.org/wiki/TracDev/PluginDevelopment 30
31. Reference: ulipad • http://code.google.com/p/ulipad/source/bro WSE/trunk/modules/Mixin. py • Another plug-in mechanism 31
32. I/O 32
33. I/O needs to be done differently. 33
34. I/O needs to be done differently. 34
35. 35
Http://s3.amazonaws.com/four.livejournal/20091117/jsconf.pdf 36
37. this is how I/O shocould be done. def sign_in (username, password): Result = dB. query (Select ...) if Len (result) = 1: token = game. sign_in (...) return token 2 dB 1 3 6 sign_in 4 5 Game 7 37
38. coroutine is the future! 38
39. gevent 39
40. gevent = libevent + greenlet 40
41. libevent • provides a mechanism for calling the callback function when a specified file descriptor event occurs • timeouts, signals 41
42. greenlet • green thread-user space-pseudo-concurrently-scheduled by VM-http://wikipedia.org/wiki/green_threads• greenlet = pythons green thread 42
43. echo server • From gevent. server Import • If _ name _ = _ main __: streamserver • Server = • def echo (socket, address): streamserver (0.0.0.0, 6000), ECHO) • fileobj = socket. makefile () • Print (Starting echo server • While true: on Port 6000) • line = fileobj. readline () • server. serve_forever () • if not line: • break • If line. strip (). lower () = quit: • Print ("client quit") • break • fileobj. write (line) • fileobj. flush () 43
44. Reference: Eurasia • http://code.google.com/p/eurasia/ 44
45. Protocol 45
46. Google protobuf • http://code.google.com/p/protobuf/• protocol description language • C ++, Java, Python and more 46
47. RPC 47
48. Abu. RPC = gevent + protobuf 48
49. Abu. RPC • smaller (benefiting from Google protobuf) • faster (benefiting from libevent) • synchronous API (benefiting from greenlet) • parallel pipeline • Two-way call 49
50. Parallel pipeline http://wiki.msgpack.org/display/MSGPACK/Design+of+RPC 50
51. echo serverfrom Abu. RPC import server, send_returnimport echo_k2as echoclass echoservice (echo. echoservice): @ send_return def echo (self, controller, request, done): Return requestserver = server (0.0.0.0, 1008), (echoservice (),) print serving... server. serve_forever () 51
52. Publish-subscribe 52
53. import message • hello, Lai. def Hello (context, name): Print hello, % S. % namemessage. sub (greet, hello) message. pub (greet, LAI) 53
54. Python-message • http://pypi.python.org/pypi/message• in-process publish-subscribe mechanism • Written by Falcon programming language • http://www.slideshare.net/laiyonghao/pyth onmessage010 • Applied to subsystems such as tasks, emails, and friends 54
55. utils 55
56. absolute32 • http://pypi.python.org/pypi/absolute32• [-2 ** 31, 2 ** 31-1] • Ubuntu 10.04 lts 32-bit/64-bit • Python 2.6/3.1 • hash • Add • CRC • Adler 56
57. Thank you. Q & ahttp: // laiyonghao.com 57

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.