Working with PyCLIPS from a web app

2011-08-16
2013-04-25
  • Maxim Kolchin
    Maxim Kolchin
    2011-08-16

    Hi folks,

    I'm developing a web based expert system engine that will use PyCLIPS.
    And I have a problem, the problem is how to run more than one CLIPS engine to run several ES in the same time?

    For example, there are 100 users who want working with the engine (load rules, load/assert facts, run ES and etc.).
    How I should give an access to the engine for each user? I think, there are a few ways:
    1) There is one CLIPS engine and each user has its own Environment instance. And it has to be blocked while the engine is busy.
    2) There are a lot of CLIPS engines and each user has its own engine.

    I think, the second way is preferred, but I don't know how implement it. What should I read?
    Have you any idea about it?

    Thanks,
    Max

     
  • Hi Max…

    As you might have noticed, CLIPS is a rather heavy inference engine. Moreover: it's definitely something stateful - whereas a web app is usually not, as long as you don't transfer the state within the session, either using something like cookies or using a state stored somewhere on the server.

    Creation of multiple CLIPS is not easy, you can create several Python instances that, in their turn, have an instance of CLIPS/PyCLIPS each. This would be expensive though, but it would guarantee a fairly good multitasking, as it would be managed by the underlying OS and NOT, for instance, the Apache web server with the mod_python module. Python interpreters in mod_python are as many as the Apache web server processes, that is much less than the actual web connections.

    There is another problem, in trying to implement such a stateful system as an ES in a multitasking/multiprocess environment: you'd have to restart CLIPS' memory at each connection, and reload its state for each user at every connection, because the mod_python interpreter could have kept the state from a previous user upon a connection. This is also very expensive in terms of time, CPU and memory: in fairly complex systems it could become annoying.

    The way I see the it, you'd rather have to build a backend, which is called by web-based frontend (with no intelligence aboard) that carries a connection ID for each user, for instance through a local socket. You can spawn a PyCLIPS Environment for every user in this case: it should be quite safe as long as you consider the module as a single resource and don't just env.Run() upon request but run the rules stepwise.

    I definitely would not implement an ES, which is far too stateful, in a web application.

    F.