P
P
p4s8x2015-01-21 13:48:41
PHP
p4s8x, 2015-01-21 13:48:41

PHP, high load. How to organize shared access to objects?

The project is a Web service, Json-API.
Initially - the load was small, about 500 records per second and using mongodb was fine.
The next step - Redis was implemented as a layer - copes well with online 25,000 people, but if you send two requests at the same time, you can get the following story:
Request 1 arrives at 0.01 second, ends at 0.04 second.
Request 2 arrives at 0.02 second, ends at 0.03 second.
Both requests modify the object. When a request comes in, the object is loaded into memory, the object is manipulated, and the object is written.
Thus, in the scheme above - changes from request 2 - will be ignored, because they will be overwritten by request 1, which knew nothing about request 2
Пока видим следующие пути решения:
1) использовать редис для организации блокировок (т.е. вообще не давать параллельного доступа к 1 объекту) - минус в увеличении ожидания ответа пользователем
2) организовать partial-update объектов (т.е. разбить объект в редисе и за "раз" апдейтить только свою часть) - не дает 100% гарантий отсутствия перезаписи
3) делать запрос объекта перед каждым изменением - очень накладно по ресурсам
4) отказаться от редис, но вот монго - не справляется(уже вынесли на сервер c SSD с кучей оперативки), хотя монго отлично поддерживает атомарные операции. Но чем заменить.. в php есть php.net/manual/ru/book.shmop.php но писать свой велосипед не хотелось бы и не понятно, будет ли он сколько то производительным.
Those. in fact, I want to achieve storage of a pool of objects in the server's memory and, when changing a parameter, be sure that it has changed in a parallel query.
What are the options?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene, 2015-01-21
@Nc_Soft

1. there are transactions in radish
2. is caching used
3. why do you need to overwrite the object so often? are there any problems with the architecture?

U
Unknown Hero, 2015-01-21
@UnknownHero

Event Sourcing should help with competition in the database.
But there may be problems with lack of memory.
Lua can help you speed up snapshot builds or add history cleanup to save memory.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question