Multi-Threading Server Applications

Using ABBYY FineReader Engine in server applications has certain specifics:

  • multiple independent requests must be handled simultaneously in multiple threads within one process
  • the Engine runs under a server operating system on a high-performance multi-CPU computer
  • using with special accounts (Network Service, Local Service, ASPNET).

When developing ABBYY FineReader Engine, the above specifics were taken into consideration and tools were included into the API which enable you to get thread-safe FineReader Engine objects as part of a server process or in separate processes. Using FineReader Engine in multiple processes allows you to create a pool of objects that work simultaneously and use the full CPU power of the server computer. This is the optimal approach in most server scenarios.

 

Loading the Engine object into a server application

The most optimal method of loading the Engine into a server application is to load it by means of COM into a separate process as an out-of-process server. This method automatically eliminates all difficulties related to multi-threading: all operations with the ABBYY FineReader Engine objects are serialized by means of COM, which allows you to create several Engine instances in several processes and work with them simultaneously from within the server process. At the same time this method is easy to use. The Engine object is loaded by using the OutprocLoader object, which implements an IEngineLoader interface.

 C# code

IEngineLoader engineLoader = new FREngine.OutprocLoader();
IEngine engine = engineLoader.InitializeEngine(…); // We got Engine in a separate process
try {
	…
} finally {
	engineLoader.ExplicitlyUnload(); // We can unload it when it is no longer needed
}

This method has one important drawback, however. When using it with special accounts, permissions may be required to run OutprocLoader for such accounts. However, this, and the need to register FREngine.dll, is not very crucial in server products, as server applications are usually installed by experienced administrators on a small number of computers.

Note:

  • Account permissions can be set up using the DCOM Config utility (either type DCOMCNFG in the command line, or select Control Panel > Administrative Tools > Component Services). In the console tree, locate the Component Services > Computers > My Computer > DCOM Config folder, right-click ABBYY FineReader 12.2 Engine Loader (Local Server), and click Properties. A dialog box will open. Click the Security tab. Under Launch Permissions, click Customize, and then click Edit to specify the accounts that can launch the application.
    Note that on a 64-bit operating system the registered DCOM-application is available in the 32-bit MMC console, which can be run using the following command line:
    mmc comexp.msc /32
  • To register FREngine.dll when installing your application on the server, use the following command line:
    regsvr32.exe /s /n /i:"<Path to the Inc folder>" "<Path to the FREngine.dll>"
    Inc folder can be found in the FineReader Engine data folder: %ProgramData%\ABBYY\SDK\12\FineReader Engine.
  • We recommend that you use a Network license both for debugging your server application and for running it.

Additionally you can manage the priority of a host process and control whether it is alive using the IHostProcessControl interface.

Other methods of loading ABBYY FineReader Engine are also available. However, they have certain specifics which considerably limit their use in server applications.

  • ABBYY FineReader Engine can be loaded by means of COM as an in-process server within the current process. This method also automatically eliminates all difficulties related to multi-threading (all operations with the ABBYY FineReader Engine objects are serialized by means of COM) and is easy to use. However, this method does not allow you to organize simultaneous processing using several instances of the Engine object, which in many ways limits the performance of the server. Another drawback of this method is that it requires registration of FREngine.dll when installing the application on an end user's computer.
  • FREngine.dll can be loaded manually. This is the standard method that was used in the previous version of ABBYY FineReader Engine. This method requires that all operations with the Engine object be performed within the same thread where the Engine object was initialized. In addition, it does not allow you to initialize more than one Engine object per process. This considerably limits the performance of the server. For this reason we do not recommend using this method. One advantage of this method is that it does not require registration of FREngine.dll when installing the application on end user's computer.

Was this article helpful?

2 out of 3 found this helpful

Have more questions? Submit a request

Recently viewed