https://gravatar.com/userimage/16926726/2de44cb9918f08ff7f430244b10bf37b.jpeg?size=256

gowinder's Blog

How to Implement a Time Service

Use a singly or doubly linked list, or a priority queue (priority_queue). Each element in the queue is a timer object. A timer object holds the time difference measured from a standard point in time (when the program started running) — the later a timer is supposed to fire, the larger this value — along with the trigger event type. If you only use a linked list, you have to re-sort after every insertion. With a priority queue the insertion position is handled automatically, so I figure the priority queue should work better, though I still need to test it. On every heartbeat (the server thread loop), the time service’s OnTicker function is called. It checks the time value of the first timer in the queue, and if the current time difference has reached or passed it, the timer is popped out and its trigger event is called. Right now there are two questions still unanswered:

Load Testing Notes 2

Yesterday I found that at login the task initialisation was hitting the database far too often. Today, to find the other hot spots for database operations, I added a database-operation counter variable: if the operations get too frequent during login or while running certain calculations, I dump the database operation log and track down the cause.

I changed the way tasks are initialised, but now the problem is that auto-activation uses WEBSERVICE, and it’s far too slow. Not counting the database query time, just calling the web service function alone costs 125MS. Way too slow — I definitely need to build a middle server.

Stress Testing Notes 1

Closed beta is almost here, so we’ve started stress testing.
1000 connections was fine, but the problems showed up after login: handling a single login takes one second, so you can imagine how long 1000 of them would take.
That obviously won’t do.
So I added some test statements to find out who was dragging things out.
In the end it turned out to be the player task initialisation at login — there are over 900 tasks, each with sub-tasks, and every sub-task does a SELECT against the database whether or not there’s a record. No wonder. Tomorrow I’ll get someone to fix it: completed tasks and tasks that haven’t started yet don’t need to be read at all. That should speed things up a lot.
Then I found another problem with log writing. In the function called on every TICK, if a CHECK-style log fires an error, it keeps writing and the server stops responding. Apart from turning off logging to disk, there’s almost nothing else you can do. When the UI thread displays things, each time it pulls a log message it now checks whether that would exceed the time available for this TICK; if it would, the unprocessed TICKs get handled next time, so the UI doesn’t freeze.

Windows Socket Notes

Error 10055: as soon as the load-test client opened 1000 connections, it threw error 10055. I looked it up and found it meant a lack of resources. Thinking about it afterwards, it must have been connecting too fast — the server couldn’t keep up, so the client’s buffer filled up. The fix is to add more threads, or pause a little between each connection.

Later I found that pausing between connections didn’t help at all; only adding threads did.

Nicolas Cage in The Family Man

https://m.media-amazon.com/images/M/MV5BYzYzMTQ4NDYtNWRkZi00NTYxLThlZDItMzI1MmU1MmU5ZWQ3XkEyXkFqcGdeQXVyNDA5Mjg5MjA@._V1_FMjpg_UX1000_.jpg

When I watched this film I was on a long business trip away from home. I wouldn’t say my career was really on the up, but at least I hadn’t yet thought about going back to Wuhan.

I saw it on an ordinary weekday, after work, with nowhere to go, alone in the office. It runs less than two hours, and yet it felt as though I had lived through a good long stretch of time alongside the protagonist, Jack. Over that stretch Jack goes through an illusory experience, transforming from a rich bachelor who has everything and therefore nothing into a homebody who puts family above all.

CD: Fat Mama's Story

https://img1.doubanio.com/view/subject/m/public/s1443060.jpg I used to always download APEs and burn my own discs, but this time was different — by chance I heard a song called “Flowers on the Sea”, and I bought the CD without a second thought!

The singer is Maria. Honestly, I’d never even heard the name before, and she performs this song to perfection — I think it’s spot on. That understated mood, a touch of melancholy, passion inside plainness — maybe that’s exactly what it’s like to live in an ordinary world, a kind of self-intoxication. Intoxicated by what? Listen to the song and you’ll find out: any little thing, as long as you savour it carefully, will always yield a trace of delight.