Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.

CEF4 is thread safe? Or can be implemented?

Post Reply
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: CEF4 is thread safe? Or can be implemented?

Post by salvadordf »

Hi,

I have no experience running CEF4Delphi inside a web service.

I guess it should be possible to use it if you create GlobalCEFApp once in the main service process and then create a bunch of TChromium in OSR mode to be reused by the web service threads.
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: CEF4 is thread safe? Or can be implemented?

Post by salvadordf »

This is "unexplored territory" for me because I've never used CEF4Delphi or any other web browser component inside a web service.

All CEF based applications have these limitations :
  • 1. CEF can only be initialized once per process : This means that GlobalCEFApp can only be created once and GlobalCEFApp.StartMainProcess can only be called once.
  • 2. In case of DLLs, plugins or things like that you need to use a different EXE for the subprocesses. I guess that a web service will need it too.
  • 3. If I remember correctly, Chromium can only create 80 browsers at the same time (I'm not 100% sure about the exact number). This is the reason why I suggested that you use a bunch of TChromium components in your case.
  • 4. Windows limits the number of subprocesses created from the main process.
  • 5. You need to use a cache directory. If you use "in-memory" cache you will easily run out of RAM.
The 3rd and 4th points are easily broken in a busy server. You need to put some limits in your server to avoid creating too many browsers and visiting too many different domains at the same time.

About the problem with 2 concurrent users : If you use a bunch of TChromium components created in the main process it should work fine but I've never tested this on a server. You should check that all CEF procedures that you need can be called from any thread.
Post Reply