Features from the xrg dungeons

This series of articles aims to guide you through a set of pending features for OpenERP. Some of them are experimental, some more mature, some need to contain their maturing process... (read more)

Thursday, June 16, 2011

RPC-JSON, FTW!

Status: RFC, beta
Gitweb: http://git.hellug.gr/?p=xrg/openerp-sandbox
Conceived: winter 2010
Implemented: June 2011



It's here, I said I would make it. :)


And it's not even part of the server. Just an addon that extends the supported HTTP protocols. At the same ports (namely 8069 and 8071). The client (library) and the server will now transparently negotiate JSON instead of XML-RPC. Using the same stack, same authentication classes (modular) as XML-RPCv2, same dispatchers, we get rid of the slow XML in favor of JSON marshalling of our RPC payloads.


In an attempt to prepare for the future, a RESTful approach has been chosen for the implementation of the RPC-JSON protocol. So, a 3rd-party client could enjoy URLs that are mapped to the ORM objects or the server's export services.
Note that the name is RPC-JSON rather than JSON-RPC. It has to be a different name, since this implementation is not strictly a vanilla JSON-RPC one. We are compatible, but not limited to a strict JSON-RPC specification. 
For example, even with a plain browser, you can issue:
GET /json/orm/db-name/res.partner/read?0=123
and fetch the data of res.partner[123] in a JSON packet. (you will be asked for http authentication, of course)

In some tests carried out, RPC-JSON seems to significantly reduce the CPU time needed at both the server and clients, regarding the RPC communication. However, the size of data has just fallen from 2.05MB to 1.61MB, because gzip encoding optimizes both cases to a matching level (note that the old XML-RPCv1 protocol, uncompressed, is 4.68MB).

3 comments:

  1. Hey - this is fantastic! I'd love to get it working, but it seems as though it won't install with OpenERP for some reason... here's the error I get:
    Traceback (most recent call last):
    File "/usr/share/pyshared/openerp-server/netsvc.py", line 489, in dispatch
    result = ExportService.getService(service_name).dispatch(method, auth, params)
    File "/usr/share/pyshared/openerp-server/service/web_services.py", line 599, in dispatch
    res = fn(db, uid, *params)
    File "/usr/share/pyshared/openerp-server/osv/osv.py", line 122, in wrapper
    return f(self, dbname, *args, **kwargs)
    File "/usr/share/pyshared/openerp-server/osv/osv.py", line 176, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
    File "/usr/share/pyshared/openerp-server/osv/osv.py", line 167, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
    File "/usr/share/pyshared/openerp-server/addons/base/module/wizard/base_module_upgrade.py", line 98, in upgrade_module
    _db, pool = pooler.restart_pool(cr.dbname, update_module=True)
    File "/usr/share/pyshared/openerp-server/pooler.py", line 60, in restart_pool
    return get_db_and_pool(db_name, force_demo, status, update_module=update_module)
    File "/usr/share/pyshared/openerp-server/pooler.py", line 39, in get_db_and_pool
    addons.load_modules(db, force_demo, status, update_module)
    File "/usr/share/pyshared/openerp-server/addons/__init__.py", line 883, in load_modules
    processed_modules.extend(load_module_graph(cr, graph, status, report=report, skip_modules=processed_modules))
    File "/usr/share/pyshared/openerp-server/addons/__init__.py", line 716, in load_module_graph
    register_class(package.name)
    File "/usr/share/pyshared/openerp-server/addons/__init__.py", line 450, in register_class
    imp.load_module(m, *fm)
    File "/usr/share/pyshared/openerp-server/addons/rpc_json/__init__.py", line 22, in
    import rpc_json_server
    File "/usr/share/pyshared/openerp-server/addons/rpc_json/rpc_json_server.py", line 30, in
    from service.websrv_lib import HTTPDir, FixSendError, HttpOptions, dummyconn, BoundStream
    ImportError: cannot import name BoundStream

    Googling didn't return any results related to BoundStream - ideas?

    ReplyDelete
  2. The implementation of RPC-JSON is based on some features (or - you can call them "hooks") that the "pg84-next" branch of the openerp-server has had for such an occasion.
    See eg. : https://github.com/xrg/openerp-server#L177
    and : https://github.com/xrg/openerp-server/blob/pg84-next/bin/service/web_services.py#L49

    So, this module will work against that series, not just the 6.0.2 one.

    ReplyDelete
  3. Ah ok - I might try to fork this code then into something that will work with 6.0.2 - Thanks!

    ReplyDelete