Unix Technical Forum

improving write performance for logging application

This is a discussion on improving write performance for logging application within the Pgsql Performance forums, part of the PostgreSQL category; --> 2B is a lot of inserts. If you had to guess, what do you think is the maximum number ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql Performance

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

 

LinkBack Thread Tools Display Modes
  #11 (permalink)  
Old 04-19-2008, 06:54 AM
Ron
 
Posts: n/a
Default Re: improving write performance for logging

2B is a lot of inserts. If you had to guess,
what do you think is the maximum number of inserts you could do in a day?

How large is each record being inserted?

How much can you put in a COPY and how many COPYs
can you put into a transactions?

What values are you using for bgwriter* and checkpoint*?

What HW on you running on and what kind of performance do you typically get?

Inquiring minds definitely want to know ;-)
Ron


At 08:54 AM 1/4/2006, Ian Westmacott wrote:
>We have a similar application thats doing upwards of 2B inserts
>per day. We have spent a lot of time optimizing this, and found the
>following to be most beneficial:
>
>1) use COPY (BINARY if possible)
>2) don't use triggers or foreign keys
>3) put WAL and tables on different spindles (channels if possible)
>4) put as much as you can in each COPY, and put as many COPYs as
> you can in a single transaction.
>5) watch out for XID wraparound
>6) tune checkpoint* and bgwriter* parameters for your I/O system
>
>On Tue, 2006-01-03 at 16:44 -0700, Steve Eckmann wrote:
> > I have questions about how to improve the

> write performance of PostgreSQL for logging
> data from a real-time simulation. We found that
> MySQL 4.1.3 could log about 1480 objects/second
> using MyISAM tables or about 1225
> objects/second using InnoDB tables, but
> PostgreSQL 8.0.3 could log only about 540
> objects/second. (test system: quad-Itanium2,
> 8GB memory, SCSI RAID, GigE connection from
> simulation server, nothing running except
> system processes and database system under test)
> >
> > We also found that we could improve MySQL

> performance significantly using MySQL's
> "INSERT" command extension allowing multiple
> value-list tuples in a single command; the rate
> for MyISAM tables improved to about 2600
> objects/second. PostgreSQL doesn't support that
> language extension. Using the COPY command
> instead of INSERT might help, but since rows
> are being generated on the fly, I don't see how
> to use COPY without running a separate process
> that reads rows from the application and uses
> COPY to write to the database. The application
> currently has two processes: the simulation and
> a data collector that reads events from the sim
> (queued in shared memory) and writes them as
> rows to the database, buffering as needed to
> avoid lost data during periods of high
> activity. To use COPY I think we would have to
> split our data collector into two processes communicating via a pipe.
> >
> > Query performance is not an issue: we found

> that when suitable indexes are added PostgreSQL
> is fast enough on the kinds of queries our
> users make. The crux is writing rows to the
> database fast enough to keep up with the simulation.
> >
> > Are there general guidelines for tuning the

> PostgreSQL server for this kind of application?
> The suggestions I've found include disabling
> fsync (done), increasing the value of
> wal_buffers, and moving the WAL to a different
> disk, but these aren't likely to produce the 3x
> improvement that we need. On the client side
> I've found only two suggestions: disable
> autocommit and use COPY instead of INSERT. I
> think I've effectively disabled autocommit by
> batching up to several hundred INSERT commands
> in each PQexec() call, and it isn’t clear
> that COPY is worth the effort in our application.
> >
> > Thanks.
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 2: Don't 'kill -9' the postmaster

>--
>Ian Westmacott <ianw@intellivid.com>
>Intellivid Corp.
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 4: Have you searched our list archives?
>
> http://archives.postgresql.org





---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12 (permalink)  
Old 04-19-2008, 06:54 AM
Tom Lane
 
Posts: n/a
Default Re: improving write performance for logging application

Steve Eckmann <eckmann@computer.org> writes:
> Thanks for the suggestion, Tom. Yes, I think I could do that. But I
> thought what I was doing now was effectively the same, because the
> PostgreSQL 8.0.0 Documentation says (section 27.3.1): "It is allowed to
> include multiple SQL commands (separated by semicolons) in the command
> string. Multiple queries sent in a single PQexec call are processed in a
> single transaction...." Our simulation application has nearly 400 event
> types, each of which is a C++ class for which we have a corresponding
> database table. So every thousand events or so I issue one PQexec() call
> for each event type that has unlogged instances, sending INSERT commands
> for all instances. For example,


> PQexec(dbConn, "INSERT INTO FlyingObjectState VALUES (...); INSERT
> INTO FlyingObjectState VALUES (...); ...");


Hmm. I'm not sure if that's a good idea or not. You're causing the
server to take 1000 times the normal amount of memory to hold the
command parsetrees, and if there are any O(N^2) behaviors in parsing
you could be getting hurt badly by that. (I'd like to think there are
not, but would definitely not swear to it.) OTOH you're reducing the
number of network round trips which is a good thing. Have you actually
measured to see what effect this approach has? It might be worth
building a test server with profiling enabled to see if the use of such
long command strings creates any hot spots in the profile.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13 (permalink)  
Old 04-19-2008, 06:54 AM
Kelly Burkhart
 
Posts: n/a
Default Re: improving write performance for logging application

On 1/4/06, Steve Eckmann <eckmann@computer.org> wrote:
>
> Thanks, Steinar. I don't think we would really run with fsync off, but I
> need to document the performance tradeoffs. You're right that my explanation
> was confusing; probably because I'm confused about how to use COPY! I could
> batch multiple INSERTS using COPY statements, I just don't see how to do it
> without adding another process to read from STDIN, since the application
> that is currently the database client is constructing rows on the fly. I
> would need to get those rows into some process's STDIN stream or into a
> server-side file before COPY could be used, right?



Steve,

You can use copy without resorting to another process. See the libpq
documentation for 'Functions Associated with the copy Command". We do
something like this:

char *mbuf;

// allocate space and fill mbuf with appropriately formatted data somehow

PQexec( conn, "begin" );
PQexec( conn, "copy mytable from stdin" );
PQputCopyData( conn, mbuf, strlen(mbuf) );
PQputCopyEnd( conn, NULL );
PQexec( conn, "commit" );

-K

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #14 (permalink)  
Old 04-19-2008, 06:54 AM
Ian Westmacott
 
Posts: n/a
Default Re: improving write performance for logging

On Wed, 2006-01-04 at 09:29 -0500, Ron wrote:
> 2B is a lot of inserts. If you had to guess,
> what do you think is the maximum number of inserts you could do in a day?


It seems we are pushing it there. Our intentions are to scale much
further, but our plans are to distribute at this point.

> How large is each record being inserted?


They are small: 32 (data) bytes.

> How much can you put in a COPY and how many COPYs
> can you put into a transactions?


These are driven by the application; we do about 60 COPYs and a couple
dozen INSERT/UPDATE/DELETEs in a single transaction. Each COPY is
doing a variable number of rows, up to several hundred. We do 15 of
these transactions per second.

> What values are you using for bgwriter* and checkpoint*?


bgwriter is 100%/500 pages, and checkpoint is 50 segments/300 seconds.
wal_buffers doesn't do much for us, and fsync is enabled.

> What HW on you running on and what kind of performance do you typically get?


The WAL is a 2-spindle (SATA) RAID0 with its own controller (ext3).
The tables are on a 10-spindle (SCSI) RAID50 with dual U320
controllers (XFS). This is overkill for writing and querying the data,
but we need to constantly ANALYZE and VACUUM in the
background without interrupting the inserts (the app is 24x7). The
databases are 4TB, so these operations can be lengthy.

--
Ian Westmacott <ianw@intellivid.com>
Intellivid Corp.


---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #15 (permalink)  
Old 04-19-2008, 06:54 AM
Steve Eckmann
 
Posts: n/a
Default Re: improving write performance for logging application

Tom Lane wrote:

>Steve Eckmann <eckmann@computer.org> writes:
>
>
>> <>Thanks for the suggestion, Tom. Yes, I think I could do that. But I
>> thought what I was doing now was effectively the same, because the
>> PostgreSQL 8.0.0 Documentation says (section 27.3.1): "It is allowed to
>> include multiple SQL commands (separated by semicolons) in the command
>> string. Multiple queries sent in a single PQexec call are processed in a
>> single transaction...." Our simulation application has nearly 400 event
>> types, each of which is a C++ class for which we have a corresponding
>> database table. So every thousand events or so I issue one PQexec() call
>> for each event type that has unlogged instances, sending INSERT commands
>> for all instances. For example,

>
>> PQexec(dbConn, "INSERT INTO FlyingObjectState VALUES (...); INSERT
>>INTO FlyingObjectState VALUES (...); ...");
>>
>>

>
>Hmm. I'm not sure if that's a good idea or not. You're causing the
>server to take 1000 times the normal amount of memory to hold the
>command parsetrees, and if there are any O(N^2) behaviors in parsing
>you could be getting hurt badly by that. (I'd like to think there are
>not, but would definitely not swear to it.) OTOH you're reducing the
>number of network round trips which is a good thing. Have you actually
>measured to see what effect this approach has? It might be worth
>building a test server with profiling enabled to see if the use of such
>long command strings creates any hot spots in the profile.
>
> regards, tom lane
>
>

No, I haven't measured it. I will compare this approach with others that
have been suggested. Thanks. -steve

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #16 (permalink)  
Old 04-19-2008, 06:54 AM
Steve Eckmann
 
Posts: n/a
Default Re: improving write performance for logging application

Kelly Burkhart wrote:

> On 1/4/06, Steve Eckmann <eckmann@computer.org
> <mailto:eckmann@computer.org>> wrote:
>
> Thanks, Steinar. I don't think we would really run with fsync off,
> but I need to document the performance tradeoffs. You're right
> that my explanation was confusing; probably because I'm confused
> about how to use COPY! I could batch multiple INSERTS using COPY
> statements, I just don't see how to do it without adding another
> process to read from STDIN, since the application that is
> currently the database client is constructing rows on the fly. I
> would need to get those rows into some process's STDIN stream or
> into a server-side file before COPY could be used, right?
>
>
> Steve,
>
> You can use copy without resorting to another process. See the libpq
> documentation for 'Functions Associated with the copy Command". We do
> something like this:
>
> char *mbuf;
>
> // allocate space and fill mbuf with appropriately formatted data somehow
>
> PQexec( conn, "begin" );
> PQexec( conn, "copy mytable from stdin" );
> PQputCopyData( conn, mbuf, strlen(mbuf) );
> PQputCopyEnd( conn, NULL );
> PQexec( conn, "commit" );
>
> -K


Thanks for the concrete example, Kelly. I had read the relevant libpq
doc but didn't put the pieces together.

Regards, Steve

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #17 (permalink)  
Old 04-19-2008, 06:54 AM
Jim C. Nasby
 
Posts: n/a
Default Re: improving write performance for logging

On Wed, Jan 04, 2006 at 11:00:38AM -0500, Ian Westmacott wrote:
> The WAL is a 2-spindle (SATA) RAID0 with its own controller (ext3).
> The tables are on a 10-spindle (SCSI) RAID50 with dual U320
> controllers (XFS). This is overkill for writing and querying the data,
> but we need to constantly ANALYZE and VACUUM in the
> background without interrupting the inserts (the app is 24x7). The
> databases are 4TB, so these operations can be lengthy.


How come you're using RAID50 instead of just RAID0? Or was WAL being on
RAID0 a typo?
--
Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com
Pervasive Software http://pervasive.com work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #18 (permalink)  
Old 04-19-2008, 06:54 AM
Ian Westmacott
 
Posts: n/a
Default Re: improving write performance for logging

On Thu, 2006-01-05 at 19:08 -0600, Jim C. Nasby wrote:
> On Wed, Jan 04, 2006 at 11:00:38AM -0500, Ian Westmacott wrote:
> > The WAL is a 2-spindle (SATA) RAID0 with its own controller (ext3).
> > The tables are on a 10-spindle (SCSI) RAID50 with dual U320
> > controllers (XFS). This is overkill for writing and querying the data,
> > but we need to constantly ANALYZE and VACUUM in the
> > background without interrupting the inserts (the app is 24x7). The
> > databases are 4TB, so these operations can be lengthy.

>
> How come you're using RAID50 instead of just RAID0? Or was WAL being on
> RAID0 a typo?


We use RAID50 instead of RAID0 for the tables for some fault-tolerance.
We use RAID0 for the WAL for performance.

I'm missing the implication of the question...

--
Ian Westmacott <ianw@intellivid.com>
Intellivid Corp.


---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #19 (permalink)  
Old 04-19-2008, 06:54 AM
Jim C. Nasby
 
Posts: n/a
Default Re: improving write performance for logging

On Fri, Jan 06, 2006 at 09:00:06AM -0500, Ian Westmacott wrote:
> On Thu, 2006-01-05 at 19:08 -0600, Jim C. Nasby wrote:
> > On Wed, Jan 04, 2006 at 11:00:38AM -0500, Ian Westmacott wrote:
> > > The WAL is a 2-spindle (SATA) RAID0 with its own controller (ext3).
> > > The tables are on a 10-spindle (SCSI) RAID50 with dual U320
> > > controllers (XFS). This is overkill for writing and querying the data,
> > > but we need to constantly ANALYZE and VACUUM in the
> > > background without interrupting the inserts (the app is 24x7). The
> > > databases are 4TB, so these operations can be lengthy.

> >
> > How come you're using RAID50 instead of just RAID0? Or was WAL being on
> > RAID0 a typo?

>
> We use RAID50 instead of RAID0 for the tables for some fault-tolerance.
> We use RAID0 for the WAL for performance.
>
> I'm missing the implication of the question...


The problem is that if you lose WAL or the data, you've lost everything.
So you might as well use raid0 for the data if you're using it for WAL.
Or switch WAL to raid1. Actually, a really good controller *might* be
able to do a good job of raid5 for WAL. Or just use raid10.
--
Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com
Pervasive Software http://pervasive.com work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #20 (permalink)  
Old 04-19-2008, 06:55 AM
Ian Westmacott
 
Posts: n/a
Default Re: improving write performance for logging

On Fri, 2006-01-06 at 10:37 -0600, Jim C. Nasby wrote:
> The problem is that if you lose WAL or the data, you've lost everything.
> So you might as well use raid0 for the data if you're using it for WAL.
> Or switch WAL to raid1. Actually, a really good controller *might* be
> able to do a good job of raid5 for WAL. Or just use raid10.


If the WAL is lost, can you lose more than the data since the last
checkpoint?

--
Ian Westmacott <ianw@intellivid.com>
Intellivid Corp.


---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 07:20 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com