1

Topic: How to subtract last in a chat and not to lose "with delay"?

The table with chat messages (id, addtime, caption... Other fields)
Messages with id are given to the client more than last it , or is not higher 15 seconds (if it  reading).
Like all it is simple, yet you do not recall that the message with id=7 can be fixed later, than the message id=9.
So read messages 6, 8, 9 never sees messages #7.
Messages are written to a chat in transactions of different type (according to the primary goal) and to change them it does not turn out.
How to learn to find all messages despite sequence ?
The only thing that comes to mind is to find all messages on time (last 15 ) and separately to keep account, what user what messages already received.
But here it is added  with list guiding  messages and its cleaning.

2

Re: How to subtract last in a chat and not to lose "with delay"?

AndryG wrote:

But here it is added  with list guiding  messages and its cleaning.

Conduct it in the RAM and problems will not be. Well, at restart, probably, you will show messages for
The last 15 seconds twice, it is not deadly to a chat.

3

Re: How to subtract last in a chat and not to lose "with delay"?

AndryG wrote:

How to learn to find all messages despite sequence ?

Order by timestamp

4

Re: How to subtract last in a chat and not to lose "with delay"?

Ivan_Pisarevsky, addtime will contain transaction starting time.
The same history, as with ID - the message with addtime=7  in 11 seconds means, and the last reading was in 9 seconds. The message is lost.
To keep account  messages too  that still. For each user it is necessary to store list ID and addtime messages.
At  a new pack to add in this queue fresh messages and to delete become outdated. If to store all in memcached, for an example unambiguously it will be necessary to do lock of this queue for a while  messages.
Locks will be for each client that any more so it is terrible, as now  a file at record )

5

Re: How to subtract last in a chat and not to lose "with delay"?

To do a DB by a central element of system of a chat - generally an architectural error.

6

Re: How to subtract last in a chat and not to lose "with delay"?

Dimitry Sibiryakov, to such decision came because of transactions. Not to make a fuss with synchronization of messages of a chat with the same file or any server of queues.
The chat is a part toy online. It is a lot of where on the code (not from players) system messages are written to a chat.

7

Re: How to subtract last in a chat and not to lose "with delay"?

AndryG wrote:

Ivan_Pisarevsky, addtime will contain transaction starting time.
The same history, as with ID - the message with addtime=7  in 11 seconds means, and the last reading was in 9 seconds. The message is lost.

Probably trigger on COMMIT helps

8

Re: How to subtract last in a chat and not to lose "with delay"?

Dimitry Sibiryakov wrote:

generally an architectural error.

DBMS usage not the greatest error Surrenders to me against remaining flaws in setting. System messages in a chat, the system reads from a chat...  lines in a chat are occupied with 4 seconds... It is cheerful more shortly.
How many there will be users? Well ten-other, well let one hundred... Such loading  pulls effortlessly, and there, you look, the author learns the task to put, yes programmers employs, if the people runs, of what (in people crowding) I personally am not assured.:-Q

9

Re: How to subtract last in a chat and not to lose "with delay"?

, describe more in detail, .

10

Re: How to subtract last in a chat and not to lose "with delay"?

m7m wrote:

Probably trigger on COMMIT helps

It that for certain? Aha, also  to apply?

11

Re: How to subtract last in a chat and not to lose "with delay"?

AndryG wrote:

Ivan_Pisarevsky, addtime will contain transaction starting time.

At I rumple a deep sclerosis, but he whispers to me that now and current_timestamp write different time. Who from them the transaction beginning, and who runtime of the operator - well for the life of me. And than it helps you - too. Whether And so it in current implementation...

12

Re: How to subtract last in a chat and not to lose "with delay"?

a teddy bear wrote:

now and current_timestamp write different time

If to cause not in psql, . And if in PSQL (execute block, trigger, procedure),
http://www.ibase.ru/time_diff/

13

Re: How to subtract last in a chat and not to lose "with delay"?

kdv wrote:

if to cause not in psql,

By no means. In long-playing  very much even you will see a difference.

14

Re: How to subtract last in a chat and not to lose "with delay"?

AndryG wrote:

the message with id=7 can be fixed later, than the message id=9.

To minimize it, it is necessary that the transaction interposing the message in a chat, operated as much as possible short time
startTransaction
insert
commit
And all this unit should work only when the user pushes button Send.

15

Re: How to subtract last in a chat and not to lose "with delay"?

kdv, it web application therefore transactions will be as much as possible short. To minimize it does not turn out - it is necessary to eliminate completely. Now works on " crutches" and one figs of the message are lost.

wrote:

to Do a DB by a central element of system of a chat - generally an architectural error.

If it is not difficult, describe more in detail, . The question of synchronization of transactions in a DB and, let us assume, files on a disk nonpluses. How it generally becomes?

16

Re: How to subtract last in a chat and not to lose "with delay"?

AndryG wrote:

As it generally becomes?

Through an application server. It receives the message from one user, delivers it
Remaining, saves in a DB. The DB in such architecture can be and the simple text file.

17

Re: How to subtract last in a chat and not to lose "with delay"?

The moderator  pushes the button "to register a clan" on the request .
Handling of request of registration (time 1) starts
While this request is processed,  in other transaction finds a chat (2).
And when transaction of registration of a clan adds in a chat the message for  "your clan is registered"... Nobody will already read it -  remembered that it subtracted all messages on 2 inclusively.
Why a chat in the table? To write in  transactions and not  chat synchronization on a separate engine and a game engine (operation was rolled away on the conflict - all sent messages in a chat were rolled away also).
Dimitry Sibiryakov, I also write an application server now - there is no on whom a decision to get rid)
I look at a branch and  I guess: it I such stupid or it stupidly spamers "philosophize". "All is wrong", " a semaphore", "at you it turns out nothing", " four seconds". Clever men, ! If I knew as it to make, I would not write on a forum and did not ask for suggestions.
Ivan_Pisarevsky, at you in a head an architectural error, time you cling to demonstration numbers. I am surprised, how you yet did not ask, why I did not specify year in date, and only time. To me   your forecast of success of the project - thrust the smilie to itself where more deeply. Game, meanwhile, works any more one year.
The eagle owl of Urfinu-Dzhusu one word prompted "sun" as to get rid of weeds. Here, I look, all forum continuous eagle owls)
Dear eagle owls, try to squeeze out from itself hardly more expanded answers - not always it turns out to understand from one word yours  thoughts smile
Thanks.
The moderator: to the Lark I recommend to familiarize with the message

18

Re: How to subtract last in a chat and not to lose "with delay"?

AndryG wrote:

  remembered that it subtracted all messages on 2 inclusively.

Here therefore it is not necessary to be perverted and stick pull-technologies there where should be
Push-technologies.

19

Re: How to subtract last in a chat and not to lose "with delay"?

AndryG wrote:

nobody will already read it -  remembered that it subtracted all messages on 2 inclusively.

You rested against the implementation, therefore and here such hogwash turns out.
It is impossible on the basis of last  the identifier to ignore the previous.
At least, for example, the identifier needs to be appropriated only at the moment of record creation in a chat then there and then should follow . Instead of in advance to give the identifier, then half an hour to wait, and to do .
Matter of course that the identifier "becomes strongly outdated". To you it after all like clear from the very first your message.
It is necessary to think, how these identifiers are produced? You in course, what they are produced in an exclusive mode?
So, for simulation of it in a message chat too should go exclusively, or , one behind another. And any parallel transactions or insertions (messages) should not be.
Even if and not exclusively, the algorithm which always delivers all new messages is all the same necessary.
In general, with a database or without, the person should see all messages which have been written in a chat. There can not be a message which came, how messages  and that the person did not see it.

AndryG wrote:

Dear eagle owls, try to squeeze out from itself hardly more expanded answers

Here not courses in programming or architecture of systems.

20

Re: How to subtract last in a chat and not to lose "with delay"?

AndryG wrote:

Why a chat in the table? To write in  transactions and not  chat synchronization on a separate engine and a game engine (operation was rolled away on the conflict - all sent messages in a chat were rolled away also).

It is necessary for you exclusively, exterior means, in separate transaction to assign numbers of groups to new records in the chat table.
In other words
1. In the table there is a column groupID which initially contains NULL
2. Periodically launched "server" code will exclusively assign groupID. Probably it is possible not periodically, and on event FB.
3. Clients find records with groupID>___. Besides - it is possible periodically, it is possible on event from FB.
As that so.

21

Re: How to subtract last in a chat and not to lose "with delay"?

kdv, I probably in your eyes really look the stupid and lazy student.
I five times read your words. You it is torn described my problem.
[quote =] It is impossible on the basis of last  the identifier to ignore the previous.

You are absolutely right - it is impossible.
[quote =] At least, for example, the identifier needs to be appropriated only at the moment of record creation in a chat then there and then should follow . Instead of in advance to give the identifier, then half an hour to wait, and to do .
Matter of course that the identifier "becomes strongly outdated". To you it after all like clear from the very first your message.

Yes, it is clear to me. It also is my current problem. "Then there and then should follow " does not roll. Practice shows, what even in a gap 20 msec let are not frequent, but regularly are in time messages will be pushed and to break queue.
[quote =] It is necessary to think, how these identifiers are produced? You in course, what they are produced in an exclusive mode?
So, for simulation of it in a message chat too should go exclusively, or , one behind another. And any parallel transactions or insertions (messages) should not be.

And how parallelism of a DBMS, transaction and here is all? For the sake of one chat  in queue all requests? I cannot go on it. Therefore decided to push chat messages in the table in a context of parallel transactions. That requests were not braked on exclusive record of messages of a chat.
[quote =] Even if and not exclusively, the algorithm which always delivers all new messages is all the same necessary.
In general, with a database or without, the person should see all messages which have been written in a chat. There can not be a message which came, how messages  and that the person did not see it.

behind such decision I also came on a forum)
Also described in the first topic a unique example what guessed - to store for each user queue already  messages. Also described inconvenience that these queues should be serviced (to clean old numbers) in an exclusive mode. But it is is specific for each user - already easier.
"programming courses". The answer " an application server" can from your belltower and should deliver all into place. But I in any way do not catch up, as this phrase answers on "algorithm which always delivers all new messages".
In the same way as well as the phrase "a DBMS here  is not necessary.  semaphores, write to the flat file.". I heard about semaphores in multi-threaded applications. But I cannot invent in any way as they help with web application to write to me to the flat file.
Now messages are written to the flat file. For a long time-for a long time there was a terrible code where "the message identifier" was unix_timestamp server request. The heap of messages was lost. A crutch in this file added ID from the DB generator. Glitches decreased, but all the same come across "a race state" - messages are written to a file not in sequence  to them ID and reading of the data breaks.
Lock long a file for "" records I cannot is very expensive for  lock.
Therefore I also decided to transfer messages to a DB -  at record and any locks. There is no mistiming " in a DB, but could not write down in a file". Now it is necessary to subtract correctly .
[quote =] There is a lath. Did not fulfill it is go to "grow".