Postgres Performance on CPU limited Platforms

Поиск
Список
Период
Сортировка
Искать

Postgres Performance on CPU limited Platforms

От:
George McCollister <georgem@novatech-llc.com>
Дата:
I'm trying to optimize postgres performance on a headless solid state
hardware platform (no fans or disks). I have the database stored on a
USB 2.0 flash drive (hdparm benchmarks reads at 10 MB/s). Performance is
limited by the 533Mhz CPU.

Hardware:
IXP425 XScale (big endian) 533Mhz 64MB RAM
USB 2.0 Flash Drive
 
Software:
Linux 2.6.21.4
postgres 8.2.5

I created a fresh database using initdb, then added one table.

Here is the create table:
CREATE TABLE archivetbl
(
  "DateTime" timestamp without time zone,
  "StationNum" smallint,
  "DeviceDateTime" timestamp without time zone,
  "DeviceNum" smallint,
  "Tagname" character(64),
  "Value" double precision,
  "Online" boolean
)
WITH (OIDS=FALSE);
ALTER TABLE archivetbl OWNER TO novatech;

I've attached my postgresql.conf

I populated the table with 38098 rows.

I'm doing this simple query:
select * from archivetbl;
 
It takes 79 seconds to complete the query (when postgres is compiled
with -O2). I'm running the query from pgadmin3 over TCP/IP.

top shows CPU usage is at 100% with 95% being in userspace. oprofile
shows memset is using 58% of the CPU cycles!

CPU: ARM/XScale PMU2, speed 0 MHz (estimated)
Counted CPU_CYCLES events (clock cycles counter) with a unit mask of
0x00 (No unit mask) count 100000
samples  %        app name                 symbol name
288445   57.9263  libc-2.5.so              memset
33273     6.6820  vmlinux                  default_idle
27910     5.6050  vmlinux                  cpu_idle
12611     2.5326  vmlinux                  schedule
8803      1.7678  libc-2.5.so              __printf_fp
7448      1.4957  postgres                 dopr
6404      1.2861  libc-2.5.so              vfprintf
6398      1.2849  oprofiled                (no symbols)
4992      1.0025  postgres                 __udivdi3
4818      0.9676  vmlinux                  run_timer_softirq


I was having trouble getting oprofile to give a back trace for memset
(probably because my libc is optimized). So I redefined MemSet to call this:
void * gmm_memset(void *s, int c, size_t n)
{
        int i=0;
        unsigned char * p = (unsigned char *)s;
        for(i=0; i '
#log_statement = 'none'			# none, ddl, mod, all
#log_hostname = off


#---------------------------------------------------------------------------
# RUNTIME STATISTICS
#---------------------------------------------------------------------------

# - Query/Index Statistics Collector -

#stats_command_string = on
#update_process_title = on

#stats_start_collector = on		# needed for block or row stats
					# (change requires restart)
#stats_block_level = off
#stats_row_level = off
stats_row_level = on
#stats_reset_on_server_start = off	# (change requires restart)


# - Statistics Monitoring -

#log_parser_stats = off
#log_planner_stats = off
#log_executor_stats = off
#log_statement_stats = off


#---------------------------------------------------------------------------
# AUTOVACUUM PARAMETERS
#---------------------------------------------------------------------------

#autovacuum = off			# enable autovacuum subprocess?
					# 'on' requires stats_start_collector
					# and stats_row_level to also be on
autovacuum = on
#autovacuum_naptime = 1min		# time between autovacuum runs
#autovacuum_vacuum_threshold = 500	# min # of tuple updates before
					# vacuum
#autovacuum_analyze_threshold = 250	# min # of tuple updates before 
					# analyze
#autovacuum_vacuum_scale_factor = 0.2	# fraction of rel size before 
					# vacuum
#autovacuum_analyze_scale_factor = 0.1	# fraction of rel size before 
					# analyze
#autovacuum_freeze_max_age = 200000000	# maximum XID age before forced vacuum
					# (change requires restart)
#autovacuum_vacuum_cost_delay = -1	# default vacuum cost delay for 
					# autovacuum, -1 means use 
					# vacuum_cost_delay
#autovacuum_vacuum_cost_limit = -1	# default vacuum cost limit for 
					# autovacuum, -1 means use
					# vacuum_cost_limit


#---------------------------------------------------------------------------
# CLIENT CONNECTION DEFAULTS
#---------------------------------------------------------------------------

# - Statement Behavior -

#search_path = '"$user",public'		# schema names
#default_tablespace = ''		# a tablespace name, '' uses
					# the default
#check_function_bodies = on
#default_transaction_isolation = 'read committed'
#default_transaction_read_only = off
#statement_timeout = 0			# 0 is disabled
#vacuum_freeze_min_age = 100000000

# - Locale and Formatting -

datestyle = 'iso, mdy'
#timezone = unknown			# actually, defaults to TZ 
					# environment setting
#timezone_abbreviations = 'Default'     # select the set of available timezone
					# abbreviations. Currently, there are
					#   Default
					#   Australia
					#   India
					# However you can also create your own
					# file in share/timezonesets/.
#extra_float_digits = 0			# min -15, max 2
#client_encoding = sql_ascii		# actually, defaults to database
					# encoding

# These settings are initialized by initdb -- they might be changed
lc_messages = 'C'			# locale for system error message 
					# strings
lc_monetary = 'C'			# locale for monetary formatting
lc_numeric = 'C'			# locale for number formatting
lc_time = 'C'				# locale for time formatting

# - Other Defaults -

#explain_pretty_print = on
#dynamic_library_path = '$libdir'
#local_preload_libraries = ''


#---------------------------------------------------------------------------
# LOCK MANAGEMENT
#---------------------------------------------------------------------------

#deadlock_timeout = 1s
#max_locks_per_transaction = 64		# min 10
					# (change requires restart)
# Note: each lock table slot uses ~270 bytes of shared memory, and there are
# max_locks_per_transaction * (max_connections + max_prepared_transactions)
# lock table slots.


#---------------------------------------------------------------------------
# VERSION/PLATFORM COMPATIBILITY
#---------------------------------------------------------------------------

# - Previous Postgres Versions -

#add_missing_from = off
#array_nulls = on
#backslash_quote = safe_encoding	# on, off, or safe_encoding
#default_with_oids = off
#escape_string_warning = on
#standard_conforming_strings = off
#regex_flavor = advanced		# advanced, extended, or basic
#sql_inheritance = on

# - Other Platforms & Clients -

#transform_null_equals = off


#---------------------------------------------------------------------------
# CUSTOMIZED OPTIONS
#---------------------------------------------------------------------------

#custom_variable_classes = ''		# list of custom variable class names

Re: Postgres Performance on CPU limited Platforms

От:
"H. Hall" <hhall1001@reedyriver.com>
Дата:
George McCollister wrote:
> I'm trying to optimize postgres performance on a headless solid state
> hardware platform (no fans or disks). I have the database stored on a
> USB 2.0 flash drive (hdparm benchmarks reads at 10 MB/s). Performance is
> limited by the 533Mhz CPU.
>
> Hardware:
> IXP425 XScale (big endian) 533Mhz 64MB RAM
> USB 2.0 Flash Drive
>   

Hmmm  ARM/XScale, 64MB.  Just curious. Are you running a Postgres server 
on a pocket pc or possibly a cell phone?

>  
> Software:
> Linux 2.6.21.4
> postgres 8.2.5
>
> I created a fresh database using initdb, then added one table.
>
> Here is the create table:
> CREATE TABLE archivetbl
> (
>   "DateTime" timestamp without time zone,
>   "StationNum" smallint,
>   "DeviceDateTime" timestamp without time zone,
>   "DeviceNum" smallint,
>   "Tagname" character(64),
>   "Value" double precision,
>   "Online" boolean
> )
> WITH (OIDS=FALSE);
> ALTER TABLE archivetbl OWNER TO novatech;
>
> I've attached my postgresql.conf
>
> I populated the table with 38098 rows.
>
> I'm doing this simple query:
> select * from archivetbl;
>  
> It takes 79 seconds to complete the query (when postgres is compiled
> with -O2). I'm running the query from pgadmin3 over TCP/IP.
>
> top shows CPU usage is at 100% with 95% being in userspace. oprofile
> shows memset is using 58% of the CPU cycles!
>
> CPU: ARM/XScale PMU2, speed 0 MHz (estimated)
> Counted CPU_CYCLES events (clock cycles counter) with a unit mask of
> 0x00 (No unit mask) count 100000
> samples  %        app name                 symbol name
> 288445   57.9263  libc-2.5.so              memset
> 33273     6.6820  vmlinux                  default_idle
> 27910     5.6050  vmlinux                  cpu_idle
> 12611     2.5326  vmlinux                  schedule
> 8803      1.7678  libc-2.5.so              __printf_fp
> 7448      1.4957  postgres                 dopr
> 6404      1.2861  libc-2.5.so              vfprintf
> 6398      1.2849  oprofiled                (no symbols)
> 4992      1.0025  postgres                 __udivdi3
> 4818      0.9676  vmlinux                  run_timer_softirq
>
>
> I was having trouble getting oprofile to give a back trace for memset
> (probably because my libc is optimized). So I redefined MemSet to call this:
> void * gmm_memset(void *s, int c, size_t n)
> {
>         int i=0;
>         unsigned char * p = (unsigned char *)s;
>         for(i=0; i         {
>                 p[i]=0;
>         }
>         return s;
> }
>
> Here are the oprofile results for the same select query.
>
> CPU: ARM/XScale PMU2, speed 0 MHz (estimated)
> Counted CPU_CYCLES events (clock cycles counter) with a unit mask of
> 0x00 (No unit mask) count 100000
> samples  %        image name               app name                
> symbol name
> -------------------------------------------------------------------------------
>   1        5.2e-04  postgres                 postgres                
> LockAcquire
>   1        5.2e-04  postgres                 postgres                
> set_ps_display
>   20        0.0103  postgres                 postgres                
> pg_vsprintf
>   116695   60.2947  postgres                 postgres                 dopr
> 116717   60.3061  postgres                 postgres                
> gmm_memset
>   116717   60.3061  postgres                 postgres                
> gmm_memset [self]
> -------------------------------------------------------------------------------
> 20304    10.4908  oprofiled                oprofiled                (no
> symbols)
>   20304    10.4908  oprofiled                oprofiled               
> (no symbols) [self]
> -------------------------------------------------------------------------------
>   4587      2.3700  vmlinux                  vmlinux                 
> rest_init
>   6627      3.4241  vmlinux                  vmlinux                 
> cpu_idle
> 11214     5.7941  vmlinux                  vmlinux                 
> default_idle
>   11214     5.7941  vmlinux                  vmlinux                 
> default_idle [self]
> -------------------------------------------------------------------------------
>   16151     8.3450  vmlinux                  vmlinux                 
> rest_init
> 9524      4.9209  vmlinux                  vmlinux                  cpu_idle
>   9524      4.9209  vmlinux                  vmlinux                 
> cpu_idle [self]
>   6627      3.4241  vmlinux                  vmlinux                 
> default_idle
> -------------------------------------------------------------------------------
> 5111      2.6408  oprofile                 oprofile                 (no
> symbols)
>   5111      2.6408  oprofile                 oprofile                
> (no symbols) [self]
>
> oprofile shows dopr is making most of the calls to memset.
>
> Are these results typical? If memset is indeed using over 50% of the CPU
> something seems seriously wrong.
>
> Should I be expecting more performance from this hardware than what I'm
> getting in these tests?
>
> Regards,
> George McCollister
>
>   
>
>   


-- 
H. Hall
ReedyRiver Group LLC
http://www.reedyriver.com

Re: Postgres Performance on CPU limited Platforms

От:
"Scott Marlowe" <scott.marlowe@gmail.com>
Дата:
On Fri, Sep 12, 2008 at 12:07 PM, H. Hall  wrote:
>
> Hmmm  ARM/XScale, 64MB.  Just curious. Are you running a Postgres server on
> a pocket pc or possibly a cell phone?
>

I would think SQLite would be a better choice on that kind of thing.
Unless you're trying to run really complex queries maybe.

-- When fascism comes to America, it will be draped in a flag and
carrying a cross - Sinclair Lewis
FAQ