Kbase 16514: Example: Using the AppServer to speed up a query (8.1A)
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  10/05/1998 |
|
Example: Using the AppServer to speed up a query (8.1A)
This Knowledgebase Entry shows a sample of using the
Progress AppServer (available starting in 8.1A) to
speed up a potentially slow query, such as a query
involving a field that is not indexed. It speeds up
query resolution by having the query resolved on the
server, using a call to a remote procedure through the
Progress AppServer. This way, only the records of interest
will be passed back over the network to the client.
Note that there is a time cost of connecting to
the AppServer which might outweigh the benefit
of using the AppServer. You can minimize this by
connecting to the AppServer at the start of any
program where you expect to use the AppServer
repeatedly, and staying connected to the AppServer
until all AppServer queries are done.
Note also that there is an additional benefit of using the
AppServer in this case, in that the building of the
temp table is interruptible by an ENDKEY, whereas
an OPEN QUERY statement that is taking a long time
to resolve is not interruptible except by a STOP.
Step 1: Compile and save the following program on
the server, while connected to a copy of the
sports database:
/* Program remote.p, compiled on Server,
available to the AppServer */
DEFINE TEMP-TABLE t-customer LIKE customer.
DEFINE OUTPUT PARAMETER TABLE FOR t-customer.
REPEAT ON ENDKEY UNDO, LEAVE,
ON STOP UNDO, LEAVE:
FIND NEXT customer
WHERE state = "MA".
CREATE t-customer.
BUFFER-COPY customer TO t-customer.
END.
/************** end of program ***********************/
Step 2: Start an AppServer on the server machine
as follows:
proapbk -H <Host-name> -S <service name> -db <db-name>
Step 3: From a client, connected to the database server,
Run the following program:
/* Program caller.p, Runs remote.p on AppServer */
DEFINE VARIABLE hAppSrv AS HANDLE NO-UNDO.
DEFINE VARIABLE ret AS LOGICAL NO-UNDO.
DEFINE TEMP-TABLE t-customer LIKE customer.
CREATE SERVER hAppSrv.
ret = hAppSrv:CONNECT ("-S <service-name> -H <host name>").
IF NOT ret THEN
RETURN ERROR "Failed to connect to AppServer".
RUN remote.p ON hAppSrv TRANSACTION DISTINCT
(OUTPUT TABLE t-customer) NO-ERROR.
FOR EACH t-customer:
DISPLAY t-customer.
END.
MESSAGE "Done".
ret = hAppSrv:DISCONNECT().
DELETE OBJECT hAppSrv.
/***************** end of program ***********************/
For more information, consult "Building Distributed
Applications Using the Progress AppServer".
Progress Software Technical Support Note # 16514