1 / 25

Locking In CFML

Locking In CFML. Locking in CFML. }. Understand Locking. - Why. - What. to lock?. - How. - When. Locking in CFML. The problem – symptoms and reasons. Agenda. Critical ressources. Shared Scope Variables. <CFLOCK>. Nested locks. Locks and pointers. Name Locks.

yardan
Download Presentation

Locking In CFML

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Locking In CFML

  2. Locking in CFML } • Understand Locking - Why - What to lock? - How - When

  3. Locking in CFML • The problem – symptoms and reasons • Agenda • Critical ressources • Shared Scope Variables • <CFLOCK> • Nested locks • Locks and pointers • Name Locks • Lock Administration

  4. Locking in CFML • Symptome für ein Locking-Problem - langsame Anwendungen - unerklärliche Verluste von Session- oder Application-Variablen • speichergierige CF-Server - Serverabstürze

  5. Locking in CFML The ability of a program to perform multiple tasks at the same time. • Multithreading Exanple: eMail client Read messages and download new messages from the server at the same time

  6. Locking in CFML Advantages • Multithreading - performance / saves time - (system-) security Drawbacks - Programs are more complicated - not easy to implement

  7. Locking in CFML ColdFusion can handle multiple requests at the same time • Multithreading in ColdFusion Every request is assigned to a thread Number of Worker Threads can be set in CF-Administrator Additional requests will be queued Within a Thread the request is serialized

  8. Locking in CFML • Critical Ressources • Shared Scope Variables Concurrent Access • Files • Component objects (COM, CORBA, Java) • All ressources that could cause • problems or loose performance if there • are multiple clients accessing them

  9. Locking in CFML • Shared Scope Variables • Server-Scope Accessible by EVERY client of EVERY application on that server • Application-Scope Accessible by EVERY client of ONE SINGLE application • Session-Scope Accessible by ONE SINGLE client of ONE SINGLE application frames, multiple submits, reload/redirection

  10. Locking in CFML • <CFLOCK> Category Attributes Identification NAME or SCOPE Type TYPE=“Exclusive” vs. TYPE=“ReadOnly” Error Handling TIMEOUT and THROWONTIMEOUT

  11. Locking in CFML • <CFLOCK> and Shared Scope Variables • Lock EVERY SINGLE access • Lock the entire scope • use the correct locking type • lock only what needs to be locked

  12. Locking in CFML • Example: store query recordset in application • variable Wrong: <CFLOCK scope="Application"Timeout="10" type="Exclusive"> <CFQUERY datasource="#DSN#"name="application.customers"> SELECT * FROM tblCustomers </CFQUERY> </CFLOCK> Better: <CFQUERY datasource="#DSN#"name=“customers"> SELECT * FROM tblCustomers </CFQUERY> <CFLOCK scope="Application"Timeout="10" type="Exclusive"> <CFSET application.customers = customers> </CFLOCK>

  13. Locking in CFML  Deadlocks possible • Nested Locks Template 1: <CFLOCK scope="Application"Timeout="10"type="Exclusive"> <CFLOCK scope="Session"Timeout="10"type="Exclusive"> Code... </CFLOCK> </CFLOCK> <CFLOCK scope="Application"Timeout="10"type="ReadOnly"> <CFLOCK scope="Application"Timeout="10"type="Exclusive"> Code... </CFLOCK> </CFLOCK> Template 2: <CFLOCK scope="Session"Timeout="10"type="Exclusive"> <CFLOCK scope="Application"Timeout="10"type="Exclusive"> Code... </CFLOCK> </CFLOCK>

  14. Locking in CFML <CFLOCK scope="Application"Timeout="10"type="Exclusive"> <CFLOCK scope="Session"Timeout="10"type="Exclusive"> <CFSET session.DSN = application.DSN> <CFSET application.bgcolor = session.bgcolor> </CFLOCK> </CFLOCK> • Nested Locks <CFLOCK scope="Application"Timeout="10"type="ReadOnly"> <CFSET dsn = application.DSN> </CFLOCK> <CFLOCK scope="Session"Timeout="10"type="ReadOnly"> <CFSET bgcolor = session.bgcolor> </CFLOCK> <CFLOCK scope="Application"Timeout="10"type="Exclusive"> <CFSET application.bgcolor = bgcolor> </CFLOCK> <CFLOCK scope="Session"Timeout="10"type="Exclusive"> <CFSET session.DSN = DSN> </CFLOCK>

  15. Locking in CFML • Avoid nested locks if at all possible (performance issues, danger of deadlocks) • Nested Locks • If you can’z avoid nesting, always lock in the following order: 1. session scope 2. application scope 3. server scope  “Local out” approach

  16. Locking in CFML <CFSET myPointer = myStruct> • Locking of Pointers Pointer: points to a structure (is NOT a real copy!) Changing the pointer also changes initial structure Shared scope variablen are structures! <CFSET application.userData = session> <CFLOCK scope="Application"Timeout="10"type="Exclusive"> <CFSET application.userData = session> </CFLOCK> <CFLOCK scope="Session"Timeout="10"type="ReadOnly"> <CFLOCK scope="Application"Timeout="10"type="Exclusive"> <CFSET application.userData = session> </CFLOCK> </CFLOCK> <CFLOCK scope="Application"Timeout="10"type="ReadOnly"> <CFSET temp = application.userData.bgcolor> </CFLOCK> <CFSET temp = application.userData.bgcolor> <CFLOCK scope="Session"Timeout="10"type="ReadOnly"> <CFLOCK scope="Application"Timeout="10"type="ReadOnly"> <CFSET temp = application.userData.bgcolor> </CFLOCK> </CFLOCK> <CFSET application.userData.bgcolor = "##EEEEEE"> <CFLOCK scope="Application"Timeout="10"type="Exclusive"> <CFSET application.userData.bgcolor = "##EEEEEE"> </CFLOCK> <CFLOCK scope="Session"Timeout="10"type="Exclusive"> <CFLOCK scope="Application"Timeout="10"type="Exclusive"> <CFSET application.userData.bgcolor = "##EEEEEE"> </CFLOCK> </CFLOCK>

  17. Locking in CFML Name idetifies the lock and denies access to protected ressource for all locks with the same name • Name Locks Use it for all critical ressources except shared scope variables, e.g.. • Verity • <CFFILE> • COM-Objects Recommended: use a naming convention!

  18. Locking in CFML Single Threaded Sessions • Lock-Administration All thread with the same sessionID are serialized  concurrent access with session variables impossible  performance drawbacks (e.g. with frames)  template timeouts more likely to occur

  19. Locking in CFML Variable Scope Lock Settings • Lock-Administration • No automatic checking or locking • Full checking • Automatic read locking

  20. Locking in CFML Variable Scope Lock Settings • Lock-Administration • No automatic checking or locking  developer is responsible for proper locking  good performance but dangerous  Use this setting for production servers with TESTED applications

  21. Locking in CFML Variable Scope Lock Settings • Lock-Administration • Full checking  every unlocked access throws an exception  Name Locks also throw exceptions  secure, but small performance drawbacks  use it for development servers  for shared Servern

  22. Locking in CFML Variable Scope Lock Settings • Lock-Administration • Automatic read locking  every read access is automatically locked  write acesses must be locked manually  quite secure, but has serious performance drawbacks • useful if you need to add locks to an older applications

  23. Locking in CFML • Summary 1. Lock EVERY access 2. If possible sum up accesses in a single lock, but, 3. Lock only what needs to be locked 4. For Shared Scope Variables always use the SCOPE attribute 5. Use the correct locking type 6. Avoid server scope on shared servers

  24. Locking in CFML 7. Avoid nested locks; if you need to nest locks, use local out approach • Summary (continued) 8. THROWONERROR=“Yes” ist useful, but, you need to catch exceptions with CFTRY/CFCATCH 9. Avoid pointers between different scopes vermeiden. Better use StructCopy() oder Duplicate(). 10. If pointer can not be avoided: lock both scopes. 11. For production servers use “No automatic checking or locking” setting (with TESTED applications only!) 12. For development server use “Full checking” setting

  25. Locking in CFML • Questions? Christoph Schmitz eMail: info@procept.net Presentation for Download available at http://www.procept.net

More Related