shmop的有关问题
shmop的问题
是这样的,我在程序中需要频繁处理一段数据,不想每次都向MySQL查询,于是把这些要用的记录取了出来,用shmop放在内存里,方便以后修改。
不过,在写的过程中,我突然想到一个并发控制上的问题,不知道该怎么解决:
function function1(){
读取内存数据
长时间操作(修改了第x1行)
写入内存数据
}
function function2(){
读取内存数据
长时间操作(修改了第x2行)
写入内存数据
}
问题就来了,如果我把function1和function2两函数,从头到尾的用信号量同步,如:
function function1(){
获取信号量
读取内存数据
长时间操作(修改了第x1行)
写入内存数据
释放信号量
}
function function2(){
获取信号量
读取内存数据
长时间操作(修改了第x2行)
写入内存数据
释放信号量
}
那么问题可以解决,但是有违我的初衷,我的初衷是想用缓存加速,但是这样做,长时间操作不能并发执行,这样必然更慢了
如果只在写入或读取的时候同步,如:
function function1(){
获取信号量
读取内存数据
释放信号量
长时间操作(修改了第x1行)
获取信号量
写入内存数据
释放信号量
}
function function2(){
获取信号量
读取内存数据
释放信号量
长时间操作(修改了第x2行)
获取信号量
写入内存数据
释放信号量
}
那么function1如果刚好读完数据,function2写入数据了,function1写入数据时就会擦掉function2写入的数据,function2就白忙活了。。。
很怀恋java Servlet,java Servlet是可以把整个对象保存在内存里,只要能获得对象的引用,修改可以只修改对应行。而php需要把对象序列化以后才能存入内存,要动是整个对象一起动,很麻烦啊。。。
不知道怎么解决,大家讨论讨论?
------解决方案--------------------
去年年底用了一次,导致内存频频出问题,PHP进程死掉,网上一查竟然是WIN XP不支持如销毁等操作。不知道WIN 2003下会不会出现同样的问题。
------解决方案--------------------
反正我操作的时候发现在XP下无法覆盖,销毁内存,只能另外开一个ID重新存储。

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











The Servlet life cycle refers to the entire process from creation to destruction of a servlet, which can be divided into three stages: 1. Initialization stage, calling the init() method to initialize the Servlet; 2. Running stage (processing requests), the container will Request to create a ServletRequest object representing an HTTP request and a ServletResponse object representing an HTTP response, and then pass them as parameters to the service() method of the Servlet; 3. Destruction phase.

Function means function. It is a reusable code block with specific functions. It is one of the basic components of a program. It can accept input parameters, perform specific operations, and return results. Its purpose is to encapsulate a reusable block of code. code to improve code reusability and maintainability.

This article will introduce to you how to create shared memory in PHP to reduce load. Here you need to understand a function shmop. Let’s follow the article to learn~

The full name of Servlet is "Java Servlet", which means small service program or service connector in Chinese. It is a program running on a Web server or application server. It serves as a request from a Web browser or other HTTP client and a database on the HTTP server or The middle layer between applications. Servlet has the characteristics of being independent of platform and protocol. Its main function is to browse and generate data interactively and generate dynamic Web content.

There are two ways to implement distributed session management in JavaServlet: 1. Session replication: Copy session data to each server. 2. Session distribution: Use a centralized storage service to store session data and access it from multiple servers. The specific implementation methods are: session replication configures true in the web. session data.

JavaServlet can be used for: 1. Dynamic content generation; 2. Data access and processing; 3. Form processing; 4. File upload; 5. Session management; 6. Filter. Example: Create a FormSubmitServlet to handle form submission, taking name and email as parameters, and redirecting to success.jsp.

In this article, we will learn about enumerate() function and the purpose of “enumerate()” function in Python. What is the enumerate() function? Python's enumerate() function accepts a data collection as a parameter and returns an enumeration object. Enumeration objects are returned as key-value pairs. The key is the index corresponding to each item, and the value is the items. Syntax enumerate(iterable,start) Parameters iterable - The passed in data collection can be returned as an enumeration object, called iterablestart - As the name suggests, the starting index of the enumeration object is defined by start. if we ignore

Detailed explanation of the role and function of the MySQL.proc table. MySQL is a popular relational database management system. When developers use MySQL, they often involve the creation and management of stored procedures (StoredProcedure). The MySQL.proc table is a very important system table. It stores information related to all stored procedures in the database, including the name, definition, parameters, etc. of the stored procedures. In this article, we will explain in detail the role and functionality of the MySQL.proc table
