用memcache 来实现聊天室的可能性探讨.该如何解决
用memcache 来实现聊天室的可能性探讨.
突然想起这么个话题,当然要做复杂的是肯定不行的,我们只探讨将文本通过memcache实现聊天应用的可能..
首先摆在我们面前的是这个key要怎么维护?有没有实现的可能?
------解决方案--------------------
由于需要记录聊天内容和聊天人的信息
所以每笔数据应该是一个“结构”而不是单一的值
鉴于聊天内容是不可修改的,所以 key 并无实际意义,递增即可
至多是取时间值
------解决方案--------------------
聊天室需要缓存的东西不是很多啊。
------解决方案--------------------
研究过python的聊天室...关注一下
------解决方案--------------------
进来学习,这一块没什么经验。
------解决方案--------------------
本来聊天室就是个蛋疼的功能。得耗费多少资本啊。
没有这方面的经验,实现的方法有多种。把聊天数据存数据库或本地文件或memcache,显示数据会用到推送。听说还可以用socket来实现。 也没测试过。不知道哪种效率高。
------解决方案--------------------
------解决方案--------------------
虽然不懂web, 但是跑fcgi做单独的聊天服务器是可行的.
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------
除非浏览器或flash本身是服务器时,如有开放端口,推技术才可能成真。
http是请求-响应式的。 是要是uri,都可请求。
猜想QQ, 每个用户都有好友的端口中。
也是有两种方式实现: 一是有数据存中央数据库;二是一个用户发言,然后向群里广播。
------解决方案--------------------
memcached的替代品?
redis吧,数据放入内存,但也支持在硬盘上持久化保存,配置正常的情况下,性能大概是memcached的十倍(网上的数据,俺自己测没打到过,但5倍以上是确认的)。
另外,做聊天室是可行的,并且也有类似的代码, redis官网有个示例,是完全用redis来做的模仿twiiter的页面。project名称好像叫“retwis”
以前也看到过设计,一般key是用散列值即可吧,比如 用户名_时间 然后md5一下之类的...
------解决方案--------------------
------解决方案--------------------
时间戳做key
由于mem 的value值是有大小限制的
可以每过一段时间生成个key 然后内部是json格式
例如
每五分钟一个key
然后把这五分钟内的聊天记录都放到mem中
然后 用户登录根据当前的时间戳来查询
不知道可否
------解决方案--------------------
呃,好吧,从目前的经验来看,如果单台服务器来做的话,私以为用长连接是不合适的,短连接做聊天室能够实现更多的访问量。
假设一台16核心16G的服务器,Nginx + PHP-FCGI的话,大概可靠并发能达到3W,那么长连接,最多也就是3W用户喽?(3W是俺自己测试的情况,俺渣....不过另外也参考了张宴的blog,姑且国内nginx的先驱者吧) 但短连接的话,就看Nginx每秒最多的request和 后端存储每秒最多request的能力了
以下是nginx和redis的单独 request能力 测试:
nginx,以phpinfo.php为测试内容
- PHP code
./webbench -c 10000 -t 30 "http://127.0.0.1/test.php" Webbench - Simple Web Benchmark 1.5 Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software. Benchmarking: GET http://127.0.0.1/test.php 10000 clients, running 30 sec. Speed=230470 pages/min, 46263036 bytes/sec. Requests: 115235 susceed, 0 failed. <br><font color="#e78608">------解决方案--------------------</font><br>没搞 过这方面,,表示很有压力。。<br><br>

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

1. Start the [Start] menu, enter [cmd], right-click [Command Prompt], and select Run as [Administrator]. 2. Enter the following commands in sequence (copy and paste carefully): SCconfigwuauservstart=auto, press Enter SCconfigbitsstart=auto, press Enter SCconfigcryptsvcstart=auto, press Enter SCconfigtrustedinstallerstart=auto, press Enter SCconfigwuauservtype=share, press Enter netstopwuauserv , press enter netstopcryptS

An unpatchable Yubico two-factor authentication key vulnerability has broken the security of most Yubikey 5, Security Key, and YubiHSM 2FA devices. The Feitian A22 JavaCard and other devices using Infineon SLB96xx series TPMs are also vulnerable.All

In PHP development, the caching mechanism improves performance by temporarily storing frequently accessed data in memory or disk, thereby reducing the number of database accesses. Cache types mainly include memory, file and database cache. Caching can be implemented in PHP using built-in functions or third-party libraries, such as cache_get() and Memcache. Common practical applications include caching database query results to optimize query performance and caching page output to speed up rendering. The caching mechanism effectively improves website response speed, enhances user experience and reduces server load.

First you need to set the system language to Simplified Chinese display and restart. Of course, if you have changed the display language to Simplified Chinese before, you can just skip this step. Next, start operating the registry, regedit.exe, directly navigate to HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlNlsLanguage in the left navigation bar or the upper address bar, and then modify the InstallLanguage key value and Default key value to 0804 (if you want to change it to English en-us, you need First set the system display language to en-us, restart the system and then change everything to 0409) You must restart the system at this point.

1. First, double-click the [This PC] icon on the desktop to open it. 2. Then double-click the left mouse button to enter [C drive]. System files will generally be automatically stored in C drive. 3. Then find the [windows] folder in the C drive and double-click to enter. 4. After entering the [windows] folder, find the [SoftwareDistribution] folder. 5. After entering, find the [download] folder, which contains all win11 download and update files. 6. If we want to delete these files, just delete them directly in this folder.

Nexo Exchange: Swiss cryptocurrency lending platform In-depth analysis Nexo is a platform that provides cryptocurrency lending services, supporting the mortgage and lending of more than 40 crypto assets, fiat currencies and stablecoins. It dominates the European and American markets and is committed to improving the efficiency, security and compliance of the platform. Many investors want to know where the Nexo exchange is registered, and the answer is: Switzerland. Nexo was founded in 2018 by Swiss fintech company Credissimo. Nexo Exchange Geographical Location and Regulation: Nexo is headquartered in Zug, Switzerland, a well-known cryptocurrency-friendly region. The platform actively cooperates with the supervision of various governments and has been in the US Financial Crime Law Enforcement Network (FinCEN) and Canadian Finance

Effective monitoring of Redis databases is essential for maintaining optimal performance, identifying potential bottlenecks, and ensuring overall system reliability. Redis Exporter Service is a robust utility designed to monitor Redis databases using Prometheus. This tutorial will guide you through the complete setup and configuration of Redis Exporter Service, ensuring you establish a monitoring solution seamlessly. By following this tutorial, you’ll achieve a fully operational monitoring setup to effectively monitor the performance metrics of your Redis database.

PiNetwork is about to launch PiBank, a revolutionary mobile banking platform! PiNetwork today released a major update on Elmahrosa (Face) PIMISRBank, referred to as PiBank, which perfectly integrates traditional banking services with PiNetwork cryptocurrency functions to realize the atomic exchange of fiat currencies and cryptocurrencies (supports the swap between fiat currencies such as the US dollar, euro, and Indonesian rupiah with cryptocurrencies such as PiCoin, USDT, and USDC). What is the charm of PiBank? Let's find out! PiBank's main functions: One-stop management of bank accounts and cryptocurrency assets. Support real-time transactions and adopt biospecies
