Jump to content

Clément

Members
  • Content Count

    380
  • Joined

  • Last visited

  • Days Won

    4

Everything posted by Clément

  1. Hi, I'm using Delphi Rio. I have this thread that respond to Windows Messages using PostThreadMessage called from the main thread or any other thread. It is fast and working fine. procedure TdhsLoggerThread.Execute; var lMsg : TMsg; lCOunt : Integer; begin inherited; fLogs := TObjectDictionary<String,TdhsLoggerItemData>.Create([doOwnsValues]); try gLoggerThreadID := ThreadID; PeekMessage( lMsg, 0 , WM_USER , WM_USER , PM_NOREMOVE ); //FTimerID := SetTimer(0,0,1000,nil); #1 lCount := 0; while GetMessage( lMsg, 0, 0 , 0 ) do begin inc(lCount); DoProcessMessages( lMsg ); // if (lCOunt mod 1000) = 0 then #2 // DoFlushLogs; #2 end; // KillTimer(0,FTimerID); #1 DoFlushLogs; finally fLogs.Free; end; end; If I run the code as posted ( commenting #1 & #2), during my stress test with 200000 calls, lCount shows the correct number of processed messages (200005). I need to FlushLogs every second, so I added the code I marked with #1, I'm receiving WM_TIMER messages, but some of my messages are lost and lCount shows 195453 calls ( The count varies but I usually losing between 5000 to 10000 messages) . Every message has information I can't loose, so missing messages is a big no no! If I comment #1 and uncomment #2 I get all the calls as expected. No problems with DoFlushLogs then, so I'm messing up SetTimer call or it is not supposed to be called the I'm calling it. Am I using correctly SetTimer? I'm trying to avoid creating another thread just to control the timer, is there another way create a timer in the same thread without loosing my messages? ( I don't want to use Sleep() ). All I need is to timely flushlogs. If there's no other way, I will create a ThreadedTimer. TIA, Clément
  2. This is what I suspected too. I managed to track every message I sent to the thread and it broke at 5k messages, the process managed to write 2k logs before going bananas. In this new design, I'm using fewer messages. One to register the Logger and One to unregister it.
  3. When I found the mistake I picture your ghostbuster sign with a " I told you so " message. Anyway, there were a lot of things to consider. I had to redesign the solution since I will have to deal with slow medias and the message queue in windows has room for 10000 messages. This is why I like this forum, it keeps me less stupid. Thanks for the heads up!
  4. @Fr0sT.Brutal thanks for the tip. Unfortunately I made a very stupid mistake. During my tests I generated over 1.000.000 posts and of course I was NOT checking the post result. Messages where stacking faster than they would be processed. Anyway, I had to redesign. To make a long story short, the routine is almost 20x faster than logging directly to a file .
  5. Googling around I found that WaitForMultipleObjects might be a better candidate since the LoggerThread will never deal with GUI messaging, and will most probably be working in a Windows Service. I wrote my message pumping using WaitForMultipleObjects but it's not working. That's the bug I'm dealing with. But as I have MsgMsgWaitForMultipleObjects working, I won't waste more than an hour figuring out what's wrong. I need to start Multi-thread test.
  6. I'm using a queue also. I'm passing data from client-part log to the thread part via PostThreadMessages. I trust windows messaging and atomic operations to avoid using Critical sections. Also I making sure that all objects allocated in the client-part context are released in the client-part. I have to deal with a small bug, but I believe that very soon I will start stress testing with multi-threads and hopefully I won't mess my installation (to much )
  7. I'm not at the office right now, but the main code is very similar to the one below: procedure Tform1.OnButton1Click( Sender : Tobject ); var lLog : IdhsLogger; begin lLog := TdhsLogger.Create('Test', TdhsLoggerWriterFileStream.Create( ExtractFilePath( ParamStr(0) ) ) ); for i := 0 to 200 * 1000 do lLog.WriteFMT('Logging test %d',[i]); end; lLog will postThreadmessages to TdhsLoggerThread ( the code I posted above ). Just by commenting the lines I got the results I wrote. When all goes well , the log file must end with: 200000: 20190917 17:02:00.999 Logging test 200000 The first number ( 200000 ) is the editors ( notepad++) line number. It must match the logging test message number. When I use SetTimer, the log ends showing: 195432: 20190917 17:02:00.999 Logging test 200000 The writing is synchronized up to 60.000 or 70.000 entries than 5.000 to 10.000 Logging test are missing. In my new implementation I'm using MsgWaitForMultipleObjects and all 200.000 logs entries are displayed. I changed my stress test to 500.000 logs entries and then to 1.000.000 log entries. The log file ended up as expected (The editor's 500000th line shows "Logging test 500000" and the 1000000th line shows "Logging test 1000000". I will revisit the implementation using SetTimer to compare the differences. Anyway MsgWaitForMultipleObjects has a 1s timeout that flushes the logs just like SetTimer triggering WM_TIMER. The exact same stress test. The classes and method calls are the same in both implementation. The only difference is how I'm dealing with the TIMEOUT.
  8. That seems to be the way to go. I avoided using it in the beginning because MsgWaitForMultipleObjectsEx handles a lot more messages and events than I actually need. But there's this parameters in the documentation where I can set QS_TIMER or QS_POSTMESSAGE that might do the trick! Thanks
  9. If I don't use timers I will have to depend on messages to flush. So I might end up with a lot of "unflushed" log. I would depend on the client to call a "flush logs", that would be wrong.
  10. This really should be fixed! Debugging this code structure will be more common as soon as 10.4 will fix inline declaration or when LSP will be released. procedure TTest.Test; begin if SomeCondition then begin var Qry := 'select * from sometable'; Check(Qry); // Breakpoint: S shows 'A' - Output in check = 'A' end; {..} if SomeOtherCondition then begin var Qry := 'select * from sometable where condition'; Check(Qry); // Breakpoint: S shows 'A' - should have been 'C' - Output in check = 'C' end; {..} while SomeCondition do begin var Qry := SomeFunction( SomeParameter ); Check(Qry); end; end; I'm not saying this construction is good or not, but if the new feature allows it, should work as advertised! Don't have much hair left to pull out.
  11. Clément

    Application blocking (suspended)

    the icon is called "econo mode" and when you hover over the leaf icon in Task Manager’s Status column, you will now see a tooltip describing what it means (this app is suspending processes to help improve system performance). My machine shows 2 applications with that leaf (Settings and Cortana). Both applications are responding. Here's another link with a better article: https://technidad.com/what-is-this-new-green-leaf-icon-in-task-manager-of-windows-10/ How the Green Leaf feature works and what it actually does As you know, the task manager is a window in which you can view all the processes. You can view all your running apps and also the different background processes. The processes that have a Green Leaf icon beside them are a bit different from the other processes. These are the processes which are actually ‘suspended’. This can save your computers RAM, without significantly affecting the performance of the processes. You could say that Windows puts these applications in the ‘Ready state’ or ‘blocks’ them from being executed by the processor. Windows could do it when the app requires a human input/output. Also, you won’t feel any lag because of the Green Leaf feature while switching between processes. A blessing for computers with lower specs It is expected that the introduction of this new feature in several versions of Windows 10 will be a blessing for computers with lower specs. The feature is so smart that it can turn your RAM more efficient than before and you can enjoy faster speeds of computing and reduced lags. By suspending the apps until you launch them the Green Leaf feature does a really good job.Also, after the app is launch you will notice in the task manager that the Green Leaf icon disappears. hth,
  12. Clément

    Application blocking (suspended)

    This might shed some light: https://superuser.com/questions/1406692/what-does-the-leaf-symbol-in-the-status-column-of-the-task-manager-mean "Do note, the faster your computer is, the less likely it is that windows needs to suspend processes. So some users with fast pc's may not see any suspended process, while people with a slower pc may see a lot of them." HTH
  13. Clément

    news about the beta of 10.3.4

    Amateurs! Delphi 10 Rock in Rio III If you insist in using X.... Delphi X-Rio III ( I should be in marketing )
  14. Clément

    Good practices with nested methods

    Hi, The code you posted is full of traps! While it's ok to play with scope you could end it with unexpected behavior when debugging should someone alter the disposition of the declarations ( There's always this guy that wants to optimize stuff). Another thing I always keep in mind. Nested methods are good candidate to private methods. Be sure to write safe code when future comes and avoid breaking working code because you WILL cut and paste that code and WILL suffer the cut and paste syndrome !
  15. Clément

    news about the beta of 10.3.4

    I guess you heard of 10.3.4 before everybody else. From the latest roadmap 10.3.3 should be released late 2019 and 10.4 was postponed to early 2020. You can check it out here: https://community.idera.com/developer-tools/b/blog/posts/august-2019-delphi-android-beta-plans-august-roadmap-update
  16. Hi, I will start a new project with Delphi Rio and ICS 8.62. I will send and receive JSON objects and I don't need to return HTML pages, at least not for the first release. Is ThttpAppSrv Ok to use for REST only , or should I use THttpSrv instead ( I might need to use SSL ). I want to build a windows service to handle my REST requests. Is there a sample I can take a look? TIA, Clément
  17. Wow! I will take a look. Thanks a lot.
  18. Clément

    Payment - Monetization - Good international PSP

    Thanks! I will have a look. I wrote my store in Delphi, it's easy to incorporate new providers. The problem is the other way around. Would the provider want to work with me? (Ingenico never reply my emails) I guess my transaction volume scared them! 😋
  19. Clément

    Payment - Monetization - Good international PSP

    Nothing is basic in my country (Take Amazon Rain Forest as the latest example) There's a lot of thing this administration must do, or else.... Anyway, selling worldwide shows how confident I am with solving our basic administration problems in a foreseeable future
  20. Clément

    Payment - Monetization - Good international PSP

    Major card is a must for me too. I released my application (VCL) with an embedded shopping cart that is powered by Stripe and Paypal. Both offers major cards and local payment methods. All purchases will end up in my business Stripe or Paypal account. Still have to see how I will handle receipts. Brazil is known as the country with most entangled taxes, so one can only hope that working with other countries will be easier.
  21. Clément

    The Embarcadero GetIt server could not be reached...

    Hi, Have you tried the new patches? http://blog.marcocantu.com/blog/2019-august-more-patches-update-getit.html HTH, Clément
  22. Clément

    August 2019 Roadmap released

    If those are included, 10.4 would be groundbreaking change! But to be honest lambda expressions and ternary operators will never happen. (Now someone from EMB. should reply to never say never 😋)
  23. Hi, Lately I've been using a lot more $IFDEF than I use to. And modifying code in the wrong block is what worries me, since there's no difference between active and unactive block. For example: {$IFDEF USE_FEATURE} { .. procedures and functions using a feature } {$else} { .. procedures and functions not using this feature } {$endif} USE_FEATURE might be defined as a project conditional define or in an included unit.( that really depends on the project) Anyway, I would like to know if there is an extension that would use syntax highlight in the {$IFDEF} block when USE_FEATURE is defined, fade the {$ELSE} block, and of course if USE_FEATURE is not defined, the $ELSE block would be colorful and $IFDEF block grayed out. TIA,
  24. {$IFDEF} doesn't have code folding per se. I need to do some extra writing: {$IFDEF USE_FEATURE} {$REGION "USE_FEATURE"} // changes in methods to use feature(s) {$ENDREGION} {$ELSE} {$REGION "NO_FEATURE"} // Original code {$ENDREGION} {$ENDIF} Even so, this will not beat a fancy parser.
  25. Not an easy job, but would be very useful. Let's see what LSP will bring, and decisions shall be made.
×