Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What kind of conflicts are you afraid of in solution 2? I assume you refer to the possibility that you are computing a mark and in the meanwhile a new mark is provided and you start the same computation again where the second computation is stored before the first. In other words, you are not having the latest average.</p> <p>Before giving an answer, I think you should just get your code working in the easiest way. Only when you are running into problems I would consider optimizations. You will need quite a number of marks and visitors (assuming web interface) before you will really benefit from any optimization. Optimize it later is my advice.</p> <p>To the answer, I would consider 3 options. I do not know Play2 so I keep my answer generic.</p> <p>1) Don't care: The change this happens is rather limited and only a problem with very high traffic. As you are only computing a temporary value (until new marks are there) I'd ignore the possibility. Next time somebody provides a mark, your stats will be correct. 1a) You could re-calculate the averages every night to make sure they are correct for the next day.</p> <p>2) Ensure the calculations are synchronized. In other words, make sure there are never 2 calculations started at the same time. There are multiple options for that and as I do not know Play2 I'd refer from giving more info.</p> <p>3) This is the nicest way to do. As you are expecting high traffic, you want to secure you can serve your customers. The last thing you want is e.g. spending 50% of your CPU power to doing calculations. One option is to make a seperate process running in the background checking once in a while the marks table. Once it detects a new mark, it will compute the average. As you have only 1 process, you limit the CPU time it takes and the load on the database. During high load, you might be a bit behing in your calculations, but this will speed up once load is lower.</p> <p>If you are really going for heavy traffic, go for option 3). Based on your question, I'd advice to take option 1) for your product, investigate option 2 to learn more about e.g. semaphores and consider option 3) as a learning exercise.</p> <p>Good luck.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload