分布式消息系统尝试(rabbitmq, celery, redis)
最近在调整游戏的后台架构,之前因为需要快速出产品,所以整个代码都揉成一团,也基本没有做任何分层处理。现在服务器端的开发也开始逐渐招进来,所以打算打算换一套统一的架构,以后做新游戏只要做其中的业务逻辑即可。 其实之前在腾讯的时候,基本不会用到
最近在调整游戏的后台架构,之前因为需要快速出产品,所以整个代码都揉成一团,也基本没有做任何分层处理。现在服务器端的开发也开始逐渐招进来,所以打算打算换一套统一的架构,以后做新游戏只要做其中的业务逻辑即可。
其实之前在腾讯的时候,基本不会用到message queue这种,所有的分布式处理都是由自己写c++ server来互相通信的。这样的处理虽然开发量稍微大一点,但是性能和灵活性确实很高。
现在自己在外面做,虽然自己已经封装了一套server的框架出来,但是毕竟还有太多的轮子需要自己制造,所以就想到了之前一直有了解过celery,来看一下这种基于message queue的任务系统能达到什么性能。
RabbitMQ
celery首推的mq是rabbitmq,所以需要先安装一下:
在mac下用brew 安装:
brew install rabbitmq
安装成功之后,即可启动server了。
不过在这之前,我们先把后台管理的插件打开:
rabbitmq-plugins enable rabbitmq_management
之后执行如下命令,启动server:
rabbitmq-server
这个时候就可以通过?http://127.0.0.1:15672/?来访问后台管理端了,默认的用户名和密码是guest guest,可以自己在页面上修改。截图如下:
?
Redis
celery也支持redis作为broker和backend,所以redis也需要安装一下,这里就不赘述了?
Celery
安装命令为:
pip install celery
?
性能测试
新建 t.py:
from celery import Celery app = Celery(backend='amqp', broker='amqp://') @app.task def add(x, y): return x + y
以及测试文件 test.py:
import time from t import add t1 = time.time() result = add.delay(1, 2) print result.get() print time.time() - t1
?
启动celery worker:
celery -A t worker --loglevel=info -c 2
执行 python test.py 输出结果为:
0.545017004013
修改 t.py 为:
from celery import Celery app = Celery(backend='redis', broker='redis://') @app.task def add(x, y): return x + y
?
测试结果为:
0.603708028793
?
无论是rabbitmq还是redis,性能都慢的让人无法接受,最终还是放弃了用celery做任务分布的想法,还是老老实实的用server通信吧。
原文地址:分布式消息系统尝试(rabbitmq, celery, redis), 感谢原作者分享。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The message has been sent but rejected by the other party. This means that the sent information has been successfully sent from the device, but for some reason, the other party did not receive the message. More specifically, this is usually because the other party has set certain permissions or taken certain actions, which prevents your information from being received normally.

General Matrix Multiplication (GEMM) is a vital part of many applications and algorithms, and is also one of the important indicators for evaluating computer hardware performance. In-depth research and optimization of the implementation of GEMM can help us better understand high-performance computing and the relationship between software and hardware systems. In computer science, effective optimization of GEMM can increase computing speed and save resources, which is crucial to improving the overall performance of a computer system. An in-depth understanding of the working principle and optimization method of GEMM will help us better utilize the potential of modern computing hardware and provide more efficient solutions for various complex computing tasks. By optimizing the performance of GEMM

On July 29, at the roll-off ceremony of AITO Wenjie's 400,000th new car, Yu Chengdong, Huawei's Managing Director, Chairman of Terminal BG, and Chairman of Smart Car Solutions BU, attended and delivered a speech and announced that Wenjie series models will be launched this year In August, Huawei Qiankun ADS 3.0 version was launched, and it is planned to successively push upgrades from August to September. The Xiangjie S9, which will be released on August 6, will debut Huawei’s ADS3.0 intelligent driving system. With the assistance of lidar, Huawei Qiankun ADS3.0 version will greatly improve its intelligent driving capabilities, have end-to-end integrated capabilities, and adopt a new end-to-end architecture of GOD (general obstacle identification)/PDP (predictive decision-making and control) , providing the NCA function of smart driving from parking space to parking space, and upgrading CAS3.0

The best version of the Apple 16 system is iOS16.1.4. The best version of the iOS16 system may vary from person to person. The additions and improvements in daily use experience have also been praised by many users. Which version of the Apple 16 system is the best? Answer: iOS16.1.4 The best version of the iOS 16 system may vary from person to person. According to public information, iOS16, launched in 2022, is considered a very stable and performant version, and users are quite satisfied with its overall experience. In addition, the addition of new features and improvements in daily use experience in iOS16 have also been well received by many users. Especially in terms of updated battery life, signal performance and heating control, user feedback has been relatively positive. However, considering iPhone14

On April 11, Huawei officially announced the HarmonyOS 4.2 100-machine upgrade plan for the first time. This time, more than 180 devices will participate in the upgrade, covering mobile phones, tablets, watches, headphones, smart screens and other devices. In the past month, with the steady progress of the HarmonyOS4.2 100-machine upgrade plan, many popular models including Huawei Pocket2, Huawei MateX5 series, nova12 series, Huawei Pura series, etc. have also started to upgrade and adapt, which means that there will be More Huawei model users can enjoy the common and often new experience brought by HarmonyOS. Judging from user feedback, the experience of Huawei Mate60 series models has improved in all aspects after upgrading HarmonyOS4.2. Especially Huawei M

Detailed explanation of the method of modifying the system date in the Oracle database. In the Oracle database, the method of modifying the system date mainly involves modifying the NLS_DATE_FORMAT parameter and using the SYSDATE function. This article will introduce these two methods and their specific code examples in detail to help readers better understand and master the operation of modifying the system date in the Oracle database. 1. Modify NLS_DATE_FORMAT parameter method NLS_DATE_FORMAT is Oracle data

Linux and Windows are two common operating systems, representing the open source Linux system and the commercial Windows system respectively. In both operating systems, there is a command line interface for users to interact with the operating system. In Linux systems, users use the Shell command line, while in Windows systems, users use the cmd command line. The Shell command line in Linux system is a very powerful tool that can complete almost all system management tasks.
![Outlook insists on trying to connect [Fix]](https://img.php.cn/upload/article/000/465/014/171029292689611.jpg?x-oss-process=image/resize,m_fill,h_207,w_330)
This article will explore the steps you can take to resolve situations where Outlook is stuck while trying to connect. No matter what version of Microsoft Office, including Microsoft 365, you may encounter this problem. This issue causes the Outlook desktop application to be unable to receive emails properly, so it becomes crucial to resolve this issue. Fix Outlook Hangs on Trying to Connect If Outlook is having trouble connecting and you find that you're not receiving new mail on the desktop app, the following suggestions may be able to help resolve the issue. Before trying these methods, check to see if your internet connection is working properly. Try restarting your router sometimes
