"intelligent" load balancing or duplex detection

Helge Blischke H.Blischke at srz-berlin.de
Thu Aug 19 05:03:28 PDT 2004


Elvin Lee wrote:
> 
> I had considered writing a backend to perform duplex detection, but I
> could not discern a way to "select" a printer in the class to perform
> the print job. Could you enlighten me on this?
The trick is to define sort of a "dummy printer" (using the PPD of the
duplex
capable one, of course) the backend of which only does job forwarding
(setting
the raw option or the document-format to
application/vnd.cups-postscript)
> 
> Basically, I was worried that even if the backend could properly detect
> that a print job required duplexing, and then sent it to the correct
> printer, wouldn't CUPS still perform a "dumb" load-balance at the
> appropriate time and select a printer from the class to process the job?
See above.
> 
> Perhaps if you made your backend available, I could use it as a model to
> build mine. :)
Use a scripting language, like Perl or Python, and follow the guidelines
in
the CUPS programmers manual.
The logic is simple: save the file to a temporary file if you get the
data from stdin,
check for duplexing (see below), print your temporary file to the real
printer
(using just the lp or lpr command), and don't forget to erase the
temporary file.
That's all.
My own stuff I mentioned previously are a bit too complex to be used as
a template.
> 
> Elvin
> 
> Helge Blischke wrote:
> > Elvin Lee wrote:
> >
> >>Robert E A Harvey wrote:
> >>
> >>>Elvin Lee wrote:
> >>>
> >>>
> >>>>The problem, of course, is that only one of the printers support
> >>>>duplexing. Is there a way that I can configure cups on the server to
> >>>>automatically send duplex jobs to one of the printers in the class,
> >>>>rather than choosing between the two?
> >>>
> >>>
> >>>I've read the official reply, but it's got me thinking.  Are these
> >>>network connected? they sound like it, being an 'N' product.
> >>>
> >>>It might be possible to create a totally separate duplex queue, pointing
> >>>separately  to the duplex machine, and print to that?  It would
> >>>certainly work with jetadmin on Solaris, I've done that sort of thing -
> >>>an A4 queue and an A5 queue onto the same machine.
> >>>
> >>>Never tried it with CUPS - my system was quite straightforward, two
> >>>printers each with a unique queue, 'cos they were not physically close.
> >>
> >>Yes, they are networked, and it is possible to have a duplex queue and a
> >>non-duplex queue. However, I would like to ideally have the feature I
> >>described previously because users will inevitably try printing duplex
> >>jobs to the non-duplex queue (or vice versa) and then we're back to
> >>square one.
> >>
> >>Of course, the alternative would be to hack the PPD files to disable the
> >>ability to print duplex jobs to the printers in the non-duplex queue...
> >>Thus if they wanted to print duplex, they would have to select the other
> >>queue. This is a potential workaround, but not really a substitute -- I
> >>feel it lacks the functionality and robustness of the solution I
> >>suggested. But I may have to set up something of this sort as Fall
> >>quarter is rapidly approaching...
> >>
> >>Thanks for taking the time to write. All help is appreciated. :)
> >>
> >
> > A workaround I've used several times for similar issues is to write a
> > special
> > (scripted) backend that checks the job for duplex printing and then
> > forwards the
> > job to the correct physical printer.
> > If you are sure that duplex printing is only selected by job attributes,
> > it is quite
> > easy to check the option string on the command line, otherwilse you'd
> > have to feed
> > the job through Ghostscript (the nulldevice for speed) and intercept the
> > setpagedevice
> > operator and the level1 compatible things (like duplexmode etc; see the
> > PPD).
> >
> > Helge
> >
> >

PostScript snippet to check for duplex printing
---snip---
%
/_sys_setpagedevice /saetpagedevice load def	% save the current original
/keyword /Duplex def		% replace "/Duplex" by what the PPD tells you for
duplexing
/setpagedevice
{
   dup			% dup the direcory reference
   % the following results in false on top of the stack if the keyword
is not
   % known in the setpagedevice's directory operand or has the value
false attached,
   % and results true if "//keyword true" is contained in the dictionary
   //keyword 2 copy known{get}{pop pop false}ifelse
   % Now "print" the result to stdout suitable for the surrounding
script
   (duplex_requested=)print == flush
   _sys_setpagedevice	% execute the original operand
}bind def
%
---snip---
If you put this snippet into a file, say query_duplex.ps, call
Ghostscript similar to this:
gs -dPARANOIDSAFER -q -sDEVICE=nullpage -c save pop -f query_duplex.ps
your_tempfile -c quit
and save the output to stdout in a variable readable by your script.

Helge

-- 
H.Blischke at srz-berlin.de
H.Blischke at srz-berlin.com
H.Blischke at acm.org




More information about the cups mailing list