danieleteti / delphimvcframework

DMVCFramework (for short) is a popular and powerful framework for WEB API in Delphi. Supports RESTful and JSON-RPC WEB APIs development.
Apache License 2.0
1.23k stars 355 forks source link

ActiveRecord connecting to database not supported with multiple client request simultaneously #653

Closed thealgorithms10 closed 1 year ago

thealgorithms10 commented 1 year ago

As checked in samples from previous build up to latest (3.2.3-radium), commonly the connecting to database was been implemented during on Controller's OnCreate or OnBeforeRouting, and other before events then to be followed by OnDestroy or OnAfterRouting with an implementation of Adding Connection at FDManager via Connection Name followed by removing the connection with Connection Name - this was simillar also in Middleware.ActiveRecord.

Attached file is the Middleware.ActiveRecord's implementation:

image

Issue here is that, this kind of implementation can't be support simultaneous request from client due to here's the scenario:

I can't provide a sample codebase on it but that's the entire scenario. Probably i can record my client's occurrence

danieleteti commented 1 year ago

Connection names are unique per thread. There is no problem using the same connection names because the actual connection name is "threadid_{connectioname}". The scenario you are talking about cannot happend. If it happens then something else (bad) is happening.

thealgorithms10 commented 1 year ago

this was already happening @danieleteti not quite sure if there are other mistakes in implementation. And this was based on the sample been given. Will attach the current video

thealgorithms10 commented 1 year ago

https://drive.google.com/file/d/1G_dEoKAm_67oOtx_9k13PxRDke62I2iJ/view?usp=sharing

Screen record via common connection implementation (OnBeforeRouting/OnBeforeAction, OnAfterRouting/OnAfterAction)

thealgorithms10 commented 1 year ago

https://drive.google.com/file/d/1clukmYVbTbhmTgyg5hykk2NroKx3-khj/view?usp=sharing

Screen record via Middleware.ActiveRecord implementation

thealgorithms10 commented 1 year ago

Can this reopen?

danieleteti commented 1 year ago

Yes, it must be investigated. Thank you for your analysis.

thealgorithms10 commented 1 year ago

Thanks! while still diagnose/creating alternative solution for it

danieleteti commented 1 year ago

I did some deep tests using the sample project "simple_api_using_mvcactiverecord" and no problems raised at all. Are you using the latest version?

image

RDP1974 commented 1 year ago

Hi Daniele,

can perhaps you redo the test using my libs, to see the speed up? https://github.com/RDP1974/Delphi64RTL

let me know if you need my help thank you kind regards

Roberto Della Pasqua ○|∆ 139ᵒ Software | Developer | Architect www.dellapasqua.comhttp://www.dellapasqua.com/

Da: Daniele Teti @.> Inviato: venerdì 21 aprile 2023 15:57 A: danieleteti/delphimvcframework @.> Cc: Subscribed @.***> Oggetto: Re: [danieleteti/delphimvcframework] ActiveRecord connecting to database not supported with multiple client request simultaneously (Issue #653)

I did some deep tests and no problem raised at all. Are you using the latest version?

[image]https://user-images.githubusercontent.com/1428644/233654689-29b3348b-b8b1-4748-b898-f704e62a2d65.png

— Reply to this email directly, view it on GitHubhttps://github.com/danieleteti/delphimvcframework/issues/653#issuecomment-1517875003, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ASJYYI2VFPLQL4BSQ3YCM7LXCKG3RANCNFSM6AAAAAAXEIER4I. You are receiving this because you are subscribed to this thread.Message ID: @.**@.>>

thealgorithms10 commented 1 year ago

Maybe @danieleteti don't use the project the sample you've been given. I don't know how to test it actually using test prototypes but the main point of the issue is this:

btw, i was using the latest 3.2.3-radium

danieleteti commented 1 year ago

Can you use the latest version please?

thealgorithms10 commented 1 year ago

yes 3.2.3-radium is that right?

danieleteti commented 1 year ago

No, the lastest version is 3.3.0-fluorine

thealgorithms10 commented 1 year ago

Ah it was released 3days ago sorry for late check. However @danieleteti i don't this this is working due to there were no changes at latest 3.3.0-fluorine related on the concern posted. But I will test.

Btw, hope the scenario given for the concern has been understood, tell me if there were other clarifications. Thank you

danieleteti commented 1 year ago

Hi,

sorry I cannot reproduce the problem. Can you provide a self-contained project wich reproduce the issue?

thealgorithms10 commented 1 year ago

Hmm okay will try to provide a prototype instead @danieleteti but i think this is quite difficult to apply a prototype since this was occurred with a concrete data. Will try it, i'll update tomorrow

thealgorithms10 commented 1 year ago

Hi @danieleteti ! My apologies on the very late response.

Anyway, I already prepared the prototype for this issue. Before this, further note that the project involved was using 3.2.1-carbon. Screenrecord presented was initially apply at latest build (3.3.0-fluorine) but not been polished etc. So, much better we will conduct a prototype to test the issue.

Below are the details of the prototype's feature - not that i've been use the basics implementation: Server

Client

Below is the prototoype project: https://drive.google.com/file/d/1J8LIEYn-75WUQeQV0G_m-pmgEJquGSnp/view?usp=sharing

Summary of the diagnose/test results:

Details of the diagnose/test results: since my dmvc is not updated, i preserve/backup the dmvc currently used and replace to the latest build 3.3.0-fluorine

I try first to test at windows.

However, our project was an Android platform, so i migrated the test to android platform

thealgorithms10 commented 1 year ago

Below are the screenshots of the errors i encountered (this was on Android platform btw). image

Webservice logs was also on the project been forwarded, i zip it. for further copy will attach here incase. Since there were logs at MiddlewareActiveRecord webservice app as said in the screenshot, maybe i will attach only the ManualActiveRecord webservice app (this was implemented via BeforeAction/AfterAction). https://drive.google.com/file/d/1wMdJS5ifGXYNBKWlxMo5PP4FNkbnYaj_/view?usp=sharing https://drive.google.com/file/d/1ZjI5qjpT7HBrL6Plv0l25ap-HKbr6Pni/view?usp=sharing

Also, i checked also the taskmanager's status while monitoring - it has a factor i think due to multiple clients was sending requests, and those errors been occurred while the computer was okay - CPU was ranged 50-60%, RAM was ranged 60-70 I guess

thealgorithms10 commented 1 year ago

With this update, i don't know if it was still valid. But I am okay to close this thread/post. But I think still needed to check the errors currently presented. Maybe at some new post

RDP1974 commented 1 year ago

Hi Daniele,

I have read you have to implement multiple concurrent ops over database? Can I suggest some things? Look, Firedac should use custom driver definition using POOLED directive, Then the Connection, Transaction and Query can be built at runtime when needed with high speed (without the connection time penalty). The components should use Unidirectional on and Live off options, to boost performances (avoiding useless live grid buildings and cursor bidirectional). Eventually do you have a thread for every connection? You can further optimize using the DB components wrapped in a TLS threadvar, so you don’t need to create and free each time. If you don’t have each connection in a separate thread, you can use the system.threading thread pool to dispatch dynamically a thread from a pool. Example: system thread pool -> TLS db component -> query (this avoid thread creation, db connection and components creation)

Probably you already know these settings so please sorry me if I’m over useless words. Kind regards.

Roberto Della Pasqua ○|∆ 139ᵒ Software | Developer | Architect www.dellapasqua.comhttp://www.dellapasqua.com/

Da: thealgorithms10 @.> Inviato: venerdì 5 maggio 2023 05:12 A: danieleteti/delphimvcframework @.> Cc: Roberto Della Pasqua @.>; Comment @.> Oggetto: Re: [danieleteti/delphimvcframework] ActiveRecord connecting to database not supported with multiple client request simultaneously (Issue #653)

With this update, i don't know if it was still valid. But I am okay to close this thread/post. But I think still needed to check the errors currently presented. Maybe at some new post

— Reply to this email directly, view it on GitHubhttps://github.com/danieleteti/delphimvcframework/issues/653#issuecomment-1535645393, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ASJYYI2EBVQWUKA5MWT5EFLXERVXPANCNFSM6AAAAAAXEIER4I. You are receiving this because you commented.Message ID: @.**@.>>