Page 1 of 1

psql half a second to start?

PostPosted: Tue Aug 11, 2009 6:46 pm
by skyd1v3r
Hello,

While this is not a concern of PT, you might have the knowledge about this:
When I start a query like psql -Upostgres -dMyBase -c"SELECT 2+2;", it takes 270 ms.
On the other hand, something like psql -Upostgres -dMyBase -c"SELECT avg(cnt_hands) FROM holdem_cache;" takes only about 280 ms. So basicly there is a period of about 269ms to start up psql.exe without accepting any query. Do you have a clue where that delay originates from, and most importantly, how I can avoid it? I´m running things inside a loop, so the 270ms DOES matter.

Thanks

Re: psql half a second to start?

PostPosted: Wed Aug 12, 2009 5:47 am
by WhiteRider
Where does 269ms come from?
You quote 270ms in the first query and 280 for the second?

Re: psql half a second to start?

PostPosted: Wed Aug 12, 2009 6:51 am
by skyd1v3r
ax+b ;)
when calculating the average of hundreds of thousands of lines takes 10ms longer than ading 2+2, then 2+2 will hardly take longer than a single ms. So I guess the b, the time to startup, to be 270-1= 269ms.

Re: psql half a second to start?

PostPosted: Wed Aug 12, 2009 9:44 am
by kraada
You'd probably be better off writing a file with all of the commands you need and using psql with the -f flag - which uses a specific input file of commands.

Then you only need to call psql once.

Re: psql half a second to start?

PostPosted: Wed Aug 12, 2009 9:48 am
by skyd1v3r
THat´s my current approach, yet it has the down that I get the results at the end of the progress - not allowing me to manipulate the query depending on former results.

Re: psql half a second to start?

PostPosted: Wed Aug 12, 2009 9:58 am
by kraada
Have you tried employing another language as a wrapper? I've had success with PHP in the past.

Re: psql half a second to start?

PostPosted: Wed Aug 12, 2009 10:04 am
by skyd1v3r
kraada wrote:Have you tried employing another language as a wrapper? I've had success with PHP in the past.


Isn´t wrapper something to eat? :oops:
Would love some details.

Re: psql half a second to start?

PostPosted: Wed Aug 12, 2009 10:09 am
by kraada
This is more general, and this will become more and more useful the more you get into things.

Basically the biggest overview picture would be to use the PHP modules to call PostgreSQL queries in a single PHP script, then just put it all in HTML and you even get nicely formatted output in your browser which, if you so desire, you can even program to be interactive . . .

Warning: this sort of stuff can get addicting. Don't forget to eat! ;)

Re: psql half a second to start?

PostPosted: Wed Aug 12, 2009 10:12 am
by skyd1v3r
Thanks a lot!

highfalutin