473,811 Members | 2,540 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question regarding Perl, DBI, and fork()

I have a job-processing backend written in perl, talking to a (of course)
postgres database. The perl app has a master process that checks the
database periodically for jobs that need processed. When there are
available jobs, it grabs some number of them (up a few hundred), and
fork()'s to create job processing processes, one per job, again up to a few
hundred.

I know the child processes inherit the db handle, as I learned the hard way
about InactiveDestroy ;) so my question is this:

Can the children (safely) use this handle to run database queries, or
should I just consider the handle garbage? I didn't want to "just try and
see" because there's always the possibility it could work "by accident"
during the low-load testing, and fail at some other time.

Relevant versions of everything are:

FreeBSD 4.8 (Tracking RELENG_4, now 4.9-RC)
PostGreSQL 7.3.4
perl 5.003 (FreeBSD default)
perl DBI 1.37
perl DBD::Pg 1.22

I'm on the list, CC directly only if you're bored. Thanks.

-Allen
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddres sHere" to ma*******@postg resql.org)

Nov 12 '05 #1
2 2450
On Sun, Oct 26, 2003 at 03:04:29PM -0500, Allen Landsidel wrote:
Can the children (safely) use this handle to run database queries, or
should I just consider the handle garbage? I didn't want to "just try and
see" because there's always the possibility it could work "by accident"
during the low-load testing, and fail at some other time.
No, you can't. Even multithread programs can't use the same connection at
the same time (they can if serialised or if they use different connections).

Now, getting rid of the handle without it closing the connection would be a
trick.
--
Martijn van Oosterhout <kl*****@svana. org> http://svana.org/kleptog/ "All that is needed for the forces of evil to triumph is for enough good
men to do nothing." - Edmond Burke
"The penalty good people pay for not being interested in politics is to be
governed by people worse than themselves." - Plato


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE/nE1oY5Twig3Ge+Y RAuC5AJ48M+224n RfrGgF9OHGl1PsH WlO1wCbBZSc
oF6pwwvw9dHy4Vi 75LQFxZw=
=Pmon
-----END PGP SIGNATURE-----

Nov 12 '05 #2
When grilled further on (Mon, 27 Oct 2003 09:40:40 +1100),
Martijn van Oosterhout <kl*****@svana. org> confessed:
On Sun, Oct 26, 2003 at 03:04:29PM -0500, Allen Landsidel wrote:
Can the children (safely) use this handle to run database queries, or
should I just consider the handle garbage? I didn't want to "just try and
see" because there's always the possibility it could work "by accident"
during the low-load testing, and fail at some other time.


No, you can't. Even multithread programs can't use the same connection at
the same time (they can if serialised or if they use different connections).

Now, getting rid of the handle without it closing the connection would be a
trick.


I've had good success setting InactiveDestroy (as Allen found), and in my
children, I re-connect to the db. Works for me, although I'm only using up to
16 children + parent.

Cheers,
Rob

--
17:35:03 up 86 days, 10:58, 4 users, load average: 2.09, 2.04, 2.00

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iEYEARECAAYFAj+ canYACgkQgy51bQ c2FFk07gCg1+bNp 1P4sMqBQHYlQEFl T/ay
BXwAn36Ra/QMftBUjpZ9Yboev KQhM9ov
=C8Ww
-----END PGP SIGNATURE-----

Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5770
by: Josh Denny | last post by:
I am trying to write a simple file transfer server in perl that will reside of both windows and linux platforms. Basically, it accepts a connection, forks a process, and then should close the child. on windows, it dies after "accumulating" 64 children opened - however, they should all (or most) have exited by that time. Any idea how to get my children to exit and free up space for more connections? Thanks - Josh here's the relevant...
3
2748
by: Myron Turner | last post by:
I'm not sure whether this question belongs entirely here or in a perl group--but probably it requires knowledge of both. I've written a perl module, currently in use, which does asynchronous searches of library databases anywhere in the world. It forks off a separate process for each database which it contacts. In the past I've had it search successfuly through more than 1000 databases, reporting back one one record from each. The...
0
3929
by: Andrew Zhilenko | last post by:
Hello, Apparently Perl caches the value of the $$ variable (PID). So if it is a process with the embedded perl, and fork was performed not from within the Perl code, but by the C code 'outside' - the value of the $$ variable stays the same. I can see this topic already have been discussed, but apparently ha not been fixed:...
1
3566
by: George Monappallil | last post by:
Hi Guys: Below is my code. How can I grab the last data of the first column of the output of egrep -n and store it in a file for comparing it against the last data next time the script is run. Is there an easier way of doing this? Your help is appreciated. ------------------------------ #!/bin/perl
1
4176
by: David Meier | last post by:
Hi all, I am not a very skilled C programmer yet and I need the help of the list bad. OK, here is the problem: I have written a SIEVE module coded in C for the cyrus imapd mail server. This module starts a Perl Script upon new mail arrival. The Perl script then does a HTTP request to an SMS gateway with the provided arguments. OK, both programs have no compilation errors or so. When I call the Perl script with appropriate arguments...
3
2822
by: MarkW | last post by:
I hope this is the correct place to post this: I am developing a web site for a e-commerce business I will be running. The site I'm setting up will be 50% store, 50% content. I'm not sure which shopping cart I'll be using yet (am looking at os-commerce and miva) but the other part will be content. I will be writing reviews of products, articles on the industry, and someday may have some blogging and forums and advertising. As for perl,...
0
2413
by: muraley | last post by:
Hi, This client-server script does bi-directional communication. Setup i used: The server script on windows 2003 server and the client on a linux machine. Since i faced issues in getting the socket work, i'm posting this. Server Side script: #!/usr/bin/perl -w # serIO.pl
1
1948
by: webotronics | last post by:
Hi, I need to add a timeout for external programs, as the external program sometimes never dies (it's a ClearQuest multisite call to the shipping server, that sometimes never ends, but simply hangs). I have three different ways of forking the call, but none works. I send the one I believe most in... use POSIX ":sys_wait_h"; my $loop = 1; $loop = $ARGV if defined $ARGV;
0
1738
by: lilly07 | last post by:
I tried a small example in perl forking. I opena connection with sql database in the parent or main program as follws: $dbh = DBI->connect("DBI:mysql:database=$database;host=$host", $user, $pass) || die "\nDB connection error!\n"; And I try to execute some mql commands and it works fine. As one of the process will take more time to finish, I open a fork as follows. And I try to do some sql commands inside the child process as below: ...
0
9730
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10651
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10392
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10136
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7671
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6893
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4341
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3020
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.