Branch: Tag:

2008-07-26

2008-07-26 01:04:24 by Stephen R. van den Berg <srb@cuci.nl>

pgsql tuned, 62% faster than old libpq postgres driver

Rev: CHANGES:1.121
Rev: lib/modules/Sql.pmod/pgsql.pike:1.8
Rev: src/modules/_PGsql/PGsql.cmod:1.5

33:   #endif   //#define NO_LOCKING 1 // This breaks the driver, do not enable,    // only for benchmarking mutex performance - #define USEPGsql 1 // Doesn't use Stdio.FILE, but PG assist + #define USEPGsql 1 // Doesn't use Stdio.FILE, but PGassist      #ifdef USEPGsql   #define UNBUFFEREDIO 1
320: Inside #if defined(USEPGsql)
  class PGassist {    inherit Stdio.File:std;    inherit _PGsql.PGsql:pg; -  void create() { +  void create(object pgsqlsess) {    std::create(); -  +  pg::setpgsqlsess(pgsqlsess);    }    int connect(string host,int port) {    int res=std::connect(host,port);
334:      final private object getsocket() {   #ifdef USEPGsql -  object lcon = PGassist(); +  object lcon = PGassist(this);   #else   #ifdef UNBUFFEREDIO    object lcon = Stdio.File();
547:    case noerror:    if(mstate==unauthenticated)    SENDCMD(({"p",plugint32(4+sizeof(sendpass)+1), -  sendpass,"\0"})); +  sendpass,"\0"}),1);    break;    default:    case protocolunsupported:
869:    PD("Portalsinflight: %d\n",portalsinflight);    if(!portalsinflight) {    PD("Sync\n"); -  SENDCMD(({"S",plugint32(4)}),1); +  SENDCMD(({"S",plugint32(4)}));    didsync=1;    if(!special) {    _decodemsg(readyforquery);
1185:    string portalname;    portalsinflight--;    if(_portal && (portalname=_portal->_portalname)) { +  int inflight=_portal->_inflight;    _portal->_portalname = UNDEFINED;    _portal = UNDEFINED; -  if(!sizeof(portalname)) -  unnamedportalinuse--; +    #ifdef DEBUGMORE    PD("Closetrace %O\n",backtrace());   #endif -  +  if(!sizeof(portalname)) +  unnamedportalinuse--; +  if(/*sizeof(portalname)||inflight*/ 1) {    PD("Close portal %s\n",portalname);    SENDCMD(({"C",plugint32(4+1+sizeof(portalname)+1), -  "P",portalname,"\0"})); +  "P",portalname,"\0"}),1);    _closesent=1;    }    } -  + }      final private string trbackendst(int c) {    switch(c) {
1307:    }    }    if(sizeof(plugbuf)) -  SENDCMD(plugbuf); // close expireds +  SENDCMD(plugbuf,1); // close expireds    PD("%O\n",plugbuf);    }    prepareds[q]=tprepared=([]);
1327:    if(!sizeof(preparedname) || !tprepared || !tprepared->preparedname) {    PD("Parse statement %s\n",preparedname);    SENDCMD(({"P",plugint32(4+sizeof(preparedname)+1+sizeof(q)+1+2), -  preparedname,"\0",q,"\0",plugint16(0)})); +  preparedname,"\0",q,"\0",plugint16(0)}),1);    PD("Query: %O\n",q);    } // sends Parameter- and RowDescription for 'S'    conn.set_read_callback(0);
1574:    if(_pgsqlsess) {    if(copyinprogress) {    PD("CopyDone\n"); -  _pgsqlsess.SENDCMD("c\0\0\0\4"); +  _pgsqlsess.SENDCMD("c\0\0\0\4",1);    }    _pgsqlsess.reload(2);    }
1705:   #endif    return getdatarow();    case commandcomplete: +  _inflight=0;    releasesession();    switch(buffer) {    case 1: