From: Yuesong W. <yue...@ya...> - 2003-08-15 17:01:26
|
Thanks for the explaination. Things make more sense now. Yuesong --- Charles Rankin <ra...@us...> wrote: > > > > > sta...@li... said: > > > Hi, > > I want to write all my test logs to a central > server. > > To minimize the network delay I want to submit the > log > > request asynchronously. I wrote a test script that > > submits mutiple asyn log requests to the remote > server > > in succession. The problem is they were not logged > in > > the order of the submission. I'm using a VB style > > language that in turn uses the C api. Following is > the > > psuedo code: > > For i = 1 To 100 > > submit2 _ > > ReqFireAndForget, _ > > "RemoteLogServer", _ > > "Log", _ > > "Log Global Logname MyLog Level Info Message " & i > > Next i > > I would expect the log message contains 1 to 100 > in > > that order, but the acutal order seems random. > > Am I doing something wrong? Is there a way to > achieve > > what I want to do? > > Thanks, > > Yuesong > > STAF is a completely multi-threaded application. > Each incoming request is > routed to a separate thread. So, when using > ReqFireAndForget, each request > is in contention with every other request. So, > depending upon network > latencies and even thread/process context switch > timing, you can see out of > order log entries as you are. > > There is no easy fix for this inside STAFProc. Even > if STAFProc queued all > incoming requests and dispersed them to threads, > network latencies could > still generate the behavior you are seeing. > > There are a few ways around this for you. > > 1) Simply do synchronous logging instead of the > FireAndForget. Depending > on the amount of logging you are doing, you may not > notice a difference. > > 2) You could attach a sequence number (and/or a > timestamp you generate) to > all your log entries (probably at the beginning of > the message). Then when > querying the log you can sort the messages by your > sequence number. > > 3) You could create a separate process/service to > which you submit all your > log requests. This separate process/service would > queue up your requests > and then do synchronous log requests. > > 4) If your program can be multi-threaded, then you > can "post" your log > messages to a queue on another thread, and have the > other thread do > synchronous logs. > > It is certainly possible for us to modify the Log > service (or create a new > one) which would do something very similar to #3 > above. Note, however, > that it is still possible (in #3 above or with a > change to the log service) > for things to get out of order due to thread > contention/scheduling, > although this would be substantially less likely to > happen. We could > probably also tweak the Log service to do a > variation of #4, which should > do sequential logging. > > If you absolutely have to have things logged in a > sequential fashion, then > you will need to do #1, #2, or #4 above. > > -- > Charles Rankin > I do not speak for IBM > __________________________________ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com |