Professional Documents
Culture Documents
Learning Objectives
What is Shared Memory ? Data Access without Buffering Data Access with Buffering by Copy Data Access with in Place Buffering Benefits for Application Programming
Guarantees
user isolation
Requires
Application development has longed for buffering data in shared memory for a long time
What is Shared Memory ? Data Access without Buffering Data Access with Buffering by Copy Data Access with in Place Buffering Benefits for Application Programming
DB
User X Session
User X Session
What is Shared Memory ? Data Access without Buffering Data Access with Buffering by Copy Data Access with in Place Buffering Benefits for Application Programming
DB
User X Session
Common Data
User X Session
User X Session
Common data
retrieved from DB, aggregated, copied (EXPORT) to SHM
Common data
retrieved from DB, aggregated, copied (EXPORT) to SHM, and copied (IMPORT) to each user session
What is Shared Memory ? Data Access without Buffering Data Access with Buffering by Copy Data Access with in Place Buffering Benefits for Application Programming
Common data
retrieved from DB directly into SHM
User X Session
Common data
retrieved from DB directly into SHM, aggregated in place
User X Session
Common data
retrieved from DB directly into SHM, aggregated in place accessed copy-free by other user sessions
User X Session
User Y Session
User Z Session
What is Shared Memory ? Data Access without Buffering Data Access with Buffering by Copy Data Access with in Place Buffering Benefits for Application Programming
access at main memory speed In place aggregation for arbitrary data structures including strings, internal tables, and references
Workbench navigation
Data is aggregated only once Ported to ABAP Shared Objects Saves 3 MB session memory per user About 100 times faster at first access
Usage Scenarios Areas and Area Instances Locking Concept Creating and Accessing Contents
Usage Scenarios
update frequency (e.g. once a day to once per hour) (Very) costly amount of data Many parallel readers, single writer
Exclusive buffers
Access by a single writer or reader Buffer content is kept across transactions
Usage Scenarios Areas and Area Instances Locking Concept Creating and Accessing Contents
Instance Root
Design Time Support Areas are defined at design time with the shared objects area manager (transaction SHMA)
Area name corresponds to a class to be generated (e.g. cl_my_area) Name of root class must be specified (e.g. cl_my_root)
Area:
cl_my_area
Transaction SHMA generates for each area a class which inherits from the abstract class cl_shm_area
cl_shm_area
cl_my_area1
cl_my_area2
cl_my_area3
Usage Scenarios Areas and Area Instances Locking Concept Creating and Accessing Contents
Locking Concept
Attaching to an Area Instance Provides access to a shared objects area instance Creates handle object Sets appropriate lock Makes reference to root object available Methods attach_for_read attach_for_write attach_for_update
User X Session User Y Session Handle Handle Instance Root
Handle
myShmHandle = cl_my_area=>attach_for_write( ).
Detaching from an Area Instance Cancels access to a shared objects area instance Invalidates handle object Releases lock Makes reference to root object unavailable Changes must be committed or rolled back Methods detach detach_commit detach_rollback
SAP AG 2004, SAP TechEd / ABAP251 / 38
Instance Root
Usage Scenarios Areas and Area Instances Locking Concept Creating and Accessing Contents
Class builder property flag special addition SHARED MEMORY ENABLED at class definition section
All objects are accessible via root object Handle provides reference to root object Example:
x = myShmHandle->root->myObject->myAttribute.
Release lock
Demo
Demo 1
Exercise
Exercise 1
Multi Attach
Method MULTI_ATTACH must be used to attach to more than one area within one internal session Precluding of dead lock situations
Preloading Automatic preloading (buffer warm-up) for area instances can be specified at design time
Requires the specification of a loader class implementing the interface if_shm_build_instance The automatically started loader runs asynchronously in a separate session (of the same user) to avoid side effects on the caller Possible options for the preload starting point Due to a read request if no active version is available Due to invalidation, i.e. if the active version becomes out of date or expires (includes above case)
Preloading
Preloading is specified at design time using transaction SHMA
Preloading Example
data: hdl type ref to zcl_my_area, excp type ref to cx_shm_no_active_version. try. hdl = zcl_my_area=>attach_for_read( ). catch cx_shm_no_active_version into excp. if excp->textid <> cx_shm_no_active_version=>build_started and excp->textid <> cx_shm_no_active_version=>build_not_finished. raise exception excp. endif. wait up to 1 seconds. hdl = zcl_my_area=>attach_for_read( ). endtry.
Versioning Example
Instance Version: active
Reader1
SAP AG 2004, SAP TechEd / ABAP251 / 57
Versioning Example
Instance Version: active Version: under construction
Reader1
SAP AG 2004, SAP TechEd / ABAP251 / 58
Writer
Versioning Example
Instance Version: active Version: under construction
Reader1 Reader2
SAP AG 2004, SAP TechEd / ABAP251 / 59
Writer
Versioning Example
Instance Version: out of date Version: active
Reader1 Reader2
SAP AG 2004, SAP TechEd / ABAP251 / 60
Versioning Example
Instance Version: out of date Version: active
Reader1 Reader2
SAP AG 2004, SAP TechEd / ABAP251 / 61
Reader3
Versioning Example
Instance Version: out of date Version: active
Reader1
SAP AG 2004, SAP TechEd / ABAP251 / 62
Reader3
Versioning Example
Instance Version: expired Version: active
Reader3
SAP AG 2004, SAP TechEd / ABAP251 / 63
Versioning Example
Instance Version: active
Reader3
SAP AG 2004, SAP TechEd / ABAP251 / 64
States of Versions
The 4 States
1. Under construction (0..1): As long as a version is being changed 2. Active (0..1): Last committed version used for further read attaches 3. Out of date (0..n): Version with still attached readers, no further read attaches possible 4. Expired (0..n): Out of date and no more readers; will be automatically garbage collected
Version active
Version expired
Versioning Concept
Versioning is defined at design time Maximum number of versions can be specified at design time Versioning guarantees that read attaches can be satisfied in general Strictly speaking a version is an area instance version
Versioning
Versioning is specified at design time using transaction SHMA
Client Dependency
Client dependency is specified at design time using transaction SHMA
Demo
Demo 2
Exercise
Exercise 2
Database
SAP AG 2004, SAP TechEd / ABAP251 / 75
Version 2
Database
SAP AG 2004, SAP TechEd / ABAP251 / 76
Version 2
Database
SAP AG 2004, SAP TechEd / ABAP251 / 77
Area Instance
Database
SAP AG 2004, SAP TechEd / ABAP251 / 78
Area Instance
Database
SAP AG 2004, SAP TechEd / ABAP251 / 79
DB commit
Propagation Motivation
Instances reside on Application Server instances
Database
Propagation Motivation
Instances reside on Application Server instances Instance changes Database
Propagation Motivation
Instances reside on Application Server instances Instance changes do not affect other servers Database
Propagation Motivation
Instances reside on Application Server instances Instance changes do not affect other servers Instance mismatch on other application servers Database
AppServer 1 Instance
Version 2
???
Propagation Solution
Instance changes are not propagated to other servers, only an invalidation record is sent
Database
AppServer 2 Instance
version1 1 Version ???
AppServer 3 Instance
version1 1 Version ???
Propagation Solution
Instance changes are not propagated to other servers, only an invalidation record is sent New versions are created at next read request via automatic preloading Database
AppServer 1 Instance
Version 2
Version 2
Propagation Propagation is automatically specified at design time for all transactional areas
Needed for area instances that shall be kept in sync on several application servers
Propagation only means a system wide invalidation of areas. Automatic preloading is used to create updated version.
SAP AG 2004, SAP TechEd / ABAP251 / 87
Transactional Areas are specified at design time using transaction SHMA Propagation is done via invalidation using the PROPAGATE methods
Displacement Displacement means that an area instance version with no active readers can be pushed out of shared memory
Dynamic area property specified at design time Recommended on 32-bit systems only
Displacement
Displacement is specified at design time using transaction SHMA
Gives tools and administrator an idea how much shared memory is needed for a certain application.
Memory Limits
Memory Limits is specified at design time using transaction SHMA
Lifetime Lifetime is defined at design time Automatic invalidation or preloading after lifetime One out of three kinds of lifetime can be specified
Up to expiry (invalidation time), invalidation Up to update (refresh time), preloading Without read access (idle time), invalidation
Lifetime
Lifetime is specified at design time using transaction SHMA
Demo
Demo 3
Exercise
Exercise 3
Session Reader
Area Instance1
Broker Instead, it is recommended to communicate with an area via a broker class that encapsulates
Area initialization Area access Lock administration Authority checks
Session Reader
Area Instance1
Area Properties - Overview The following properties can be specified at design time
Versioning Preloading Transactional Propagation Client dependency Displacement Memory limits Lifetime
Technical
Consistency check for types used at area build-up and attach time Garbage collection for area instances Copy-on-write becomes copy-on-detach for internal tables and strings
Summary ABAP Shared Objects is used to share common data between different session Coarse granular locking concept supports shared buffer or exclusive buffer Versioning is used to implement high available services Transactional areas are used to synchronize shared object instances with database Propagation is used to synchronize shared object instances on different application server
SAP AG 2004, SAP TechEd / ABAP251 / 105
Further Information
Public Web:
www.sap.com SAP Developer Network: www.sdn.sap.com SAP Customer Services Network: www.sap.com/services/
Questions?
Q&A
SAP AG 2004, SAP TechEd / ABAP251 / 108
Feedback
Please complete your session evaluation. Be courteous deposit your trash, and do not take the handouts for the following session.
Thank You !
permission of SAP AG. The information contained herein may be changed without prior notice.
Some software products marketed by SAP AG and its distributors contain proprietary software components of other
software vendors.
Microsoft, Windows, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation. IBM, DB2, DB2 Universal Database, OS/2, Parallel Sysplex, MVS/ESA, AIX, S/390, AS/400, OS/390, OS/400, iSeries,
pSeries, xSeries, zSeries, z/OS, AFP, Intelligent Miner, WebSphere, Netfinity, Tivoli, and Informix are trademarks or registered trademarks of IBM Corporation in the United States and/or other countries.
Oracle is a registered trademark of Oracle Corporation. UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group. Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered
implemented by Netscape.
MaxDB is a trademark of MySQL AB, Sweden. SAP, R/3, mySAP, mySAP.com, xApps, xApp, SAP NetWeaver and other SAP products and services mentioned herein
as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and in several other countries all over the world. All other product and service names mentioned are the trademarks of their respective companies. Data contained in this document serves informational purposes only. National product specifications may vary.
These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated
companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.
SAP AG 2004, SAP TechEd / ABAP251 / 110