cerr <> wrote:
> On Aug 26, 1:13Â*pm, Ben Bacarisse <ben.use...@bsb.me.uk> wrote:
> > cerr <ron.egg...@gmail.com> writes:
> > > I have a major performance issue with an application that is inserting
> > > strings into a database.
> > > I'm not quite sure but we see major backlogs and it's only about 6MB
> > > that it would be inserting in 24 hours. That should not be a major
> > > problem i would say.
> >
> > I don't think you have a C problem...
> >
> >
> >
> > > The way this logserver is working is:
> > > while (1)
> > > {
> > > send message off to syslog on port 1515 which is on the same host.
> > > /*message parsing with strtok and other standard C function calls.*/
> > > sprintf(query,"insert into logs(source,date,time,program,msg)values
> > > ('%s','%d-%d-%s','%s','%s','%s[%s:%s');",
> > > Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â*_source,
> > > Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â*t->tm_year+1900,month,_date,
> > > Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â*_time,
> > > Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â*_program,
> > > Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â*_program,_program_name,newmsg
> > > Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â*);
> > > Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â*cout << "INSERT Query: " << query << endl;
> > > Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â*_update_db(_source,query);
> > > }
> >
> > ... because this seems to be C++. Â*But even so, I would want to look
> > at the database first. Â*(Well, after checking that this sprintf does
> > not overflow it's buffer.)
> well query is a char array of 1024 elements - which should be enough -
> it also does not crash because of a segmentation fault or similar.
> The right thing to do is, I understand, to verify the string size and
> that it would not overflow the query buffer. But how can I verify the
> string size is =< 1024? Before actually putting the string together.
The first simple test would be to double (or triple or whatever)
the length of the char array. That should be a thing of a few
seconds and, if the problem goes away with that, it's at least
a hint that this might be related to the problem. Then you could
try to use snprintf() with which you can set an upper limit on
the number of chars put into the string and which should return
how many actually where (or would have been) needed. Thus you can
check if the string was successfully output or if you have to try
again with a longer char array. Of course, this advice has to be
taken with a grain of salt since snprintf() is a C99 function and
you seem to be writing C++ and I don't know if it exists in C++...
If not C++ perhaps has some function that automaticallt allocates
a char array large enough (similar to the non-standard asprintf()
function)...
But my (unqualified) gut feeling is also (to be confirmed by the
above test) is that there's some problem with the database and not
something related to C/C++.
Regards, Jens
--
\ Jens Thoms Toerring ___
\__________________________
http://toerring.de