php内存消耗和,高并发处理,php排序。
做了一个sql查询,还通过了获取的数组下标来排序。但是前辈说会有大量访问的时候这样很消耗内存,网上看了下好多说的方法是做cache,有没有其他的方法处理呢?
回复讨论(解决方案)
你的语句,不会很消耗内存。activeNum是索引就可以了。
当然有cache是最好的。
你的语句,不会很消耗内存。activeNum是索引就可以了。
当然有cache是最好的。
要是有几十万上百万的数据,每次有人访问index就去取一次不会消耗资源吗?
如果加索引的话,加什么索引好呢?这个字段是随时变化的
你的语句,不会很消耗内存。activeNum是索引就可以了。
当然有cache是最好的。
要是有几十万上百万的数据,每次有人访问index就去取一次不会消耗资源吗?
如果加索引的话,加什么索引好呢?这个字段是随时变化的
如果数据值是唯一的 就加唯一索引 否则加普通索引
如果mysql表数据多 几百万的时候 那需要考虑分表
1、没看到 数组下标来排序 的代码
2、activeNum 上应有索引(普通索引即可)
3、你知道访问数据库和访问 cache 的区别吗?
将数据库的压力转嫁到 cache 就一定合适吗?
如果有有几十万上百万的数据,那么你的 cache 策略是什么?
1、没看到 数组下标来排序 的代码
2、activeNum 上应有索引(普通索引即可)
3、你知道访问数据库和访问 cache 的区别吗?
将数据库的压力转嫁到 cache 就一定合适吗?
如果有有几十万上百万的数据,那么你的 cache 策略是什么?
activeNum 是数字型,用索引也有效吗?一直以为 索引只用在where作用的字段上,排序的字段也可以用索引吗
排序也可以用到索引,不然数据量很大,不适用索引,你数据库不是崩溃。
1、没看到 数组下标来排序 的代码
2、activeNum 上应有索引(普通索引即可)
3、你知道访问数据库和访问 cache 的区别吗?
将数据库的压力转嫁到 cache 就一定合适吗?
如果有有几十万上百万的数据,那么你的 cache 策略是什么?
目前 activeNum这个字段没有加索引。
EXPLAIN 你的查询指令
MySQL 会给你有益的建议!而不是自己想当然的说
EXPLAIN 你的查询指令
MySQL 会给你有益的建议!而不是自己想当然的说
用命令查出来貌似不能用索引,我现在想到的一个办法是,新建一个rank表把用户的id,排名根据数组取下标放到rank表里面,然后在新表里面加一个uid等于0的字段,排名那里放我写入进去的时间,每次来取排名的时候先取uid=0的时间,对比当前时间,如果大于30分钟,那么就重新去active表读取一次排名放到rank表里面。不知道这方法可行么?
possible_key 是可被使用的索引,由于你没有对 activeNum 做索引,自然就没有啦
于是 Extra 列就有了 filesort,表示用了一个临时文件来对 activeNum 进行排序
possible_key 是可被使用的索引,由于你没有对 activeNum 做索引,自然就没有啦
于是 Extra 列就有了 filesort,表示用了一个临时文件来对 activeNum 进行排序
好吧,我再捣鼓捣鼓,php在linux里面有没有区分是否线程安全呢?每个用户访问一次比如我写了一个DB调用数据库,是只引用一次,所有用户都用的这一个,还是每个人都是独立的呢?
每个人都是独立的
你可以试试 单例模式, 把结果存在静态变量中试试
如果查询的量非常大,而数据又不是实时的可以做缓存来处理.但是如果数据又要是实时的 我觉得先找出瓶颈在什么地方,普通的索引等优化这些都是基础。
谢谢大家,用临时表做缓存解决了。

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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











In the Go framework architecture, the key strategies to improve high concurrency processing capabilities are: utilizing the lightweight concurrency mechanism of Goroutine to execute tasks in parallel and improve CPU utilization. Use concurrent channels for safe and efficient data exchange between coroutines to ensure data consistency and concurrency. Implement an asynchronous processing mechanism to move time-consuming tasks to the background for execution to avoid blocking request responses and improve response capabilities.

Nginx server's high concurrency processing and request response optimization skills In today's Internet era, the website's high concurrency processing and request response speed directly affect the user experience. As a high-performance, multi-functional server software, Nginx can help us achieve high concurrency processing and request response optimization. This article will introduce several commonly used techniques and code examples to help readers better understand how to use Nginx to achieve high concurrency processing and request response optimization. 1. Using reverse proxy Nginx’s reverse proxy function can help us

PHP and SQLite: How to handle big data and high concurrency In today's Internet era, handling big data and high concurrency are common challenges faced by developers. PHP is a very popular server-side scripting language and SQLite is a lightweight embedded database. Their combination can provide an efficient and scalable solution. This article will introduce how to use PHP and SQLite to handle big data and high concurrency, and attach relevant code examples. 1. Processing big data When we need to process a large amount of data, S

How to use caching technology to solve the problem of high concurrency processing in PHP. Due to the rapid development of the Internet, today's websites and applications are facing increasingly high concurrent visits. When a large number of users access a PHP website at the same time, the traditional PHP script execution method may cause server performance to decrease, response time to become longer, and even a crash to occur. In order to solve this problem, we can use caching technology to improve the concurrent processing capabilities of the PHP website. What is caching technology? Caching technology is to temporarily store some frequently accessed data

As the Internet continues to develop, there are more and more websites and web applications of various types. At this time, dealing with high concurrency has become an inevitable problem. High concurrency is not just a problem of large visits, but also the problem of multiple requests being initiated at the same time. For web applications, the ability to handle multiple requests is also the ability to process concurrently. In PHP, the swoole extension provides a very excellent model to handle high concurrent requests. The Swoole extension is open source and is similar to an extension of the PHP language.

How to use distributed locks to improve PHP's high concurrency processing capabilities. In today's Internet applications, high concurrency processing capabilities are a key issue. As the number of users grows and the business expands, how to effectively handle concurrent requests has become a challenge that every developer must solve. In PHP applications, we can use distributed locks to improve the system's high concurrent processing capabilities. This article will introduce the concept and principle of distributed locks, and show how to use distributed locks in PHP applications through code examples. 1. The concept and principle of distributed locks. Distributed locks can be understood.

Building an online voting application using Node.js and Redis: How to deal with high concurrency. With the development of the Internet, more and more applications need to handle high concurrency situations. Online voting applications are a typical high-concurrency scenario. Users submit a large number of voting requests in a short period of time. The application needs to be able to process these requests quickly and maintain data consistency. This article will introduce how to use Node.js and Redis to build a highly concurrent online voting application. Introduction to Redis Redis is a memory-based key-value database, so

With the rapid development of the mobile Internet, more and more applications need to support high concurrency and high load processing, and PHP, as an open source scripting language, has become the mainstream of many website application development, especially in the Internet field. middle. However, when PHP is used for API development, it faces some difficulties, including how to handle high concurrency and high load. This article will introduce some best practices for dealing with these issues. 1. Horizontal Scaling Horizontal scaling is a common method of responding to high concurrency and load by increasing the number of servers or
