# Fast proxy

**URL:** <https://www.ruby-forum.com/t/fast-proxy/193179>\
**Category:** Ruby\
**Created:** [August 12, 2010, 3:28pm UTC](https://www.ruby-forum.com/t/fast-proxy/193179 "2010-08-12T15:28:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![di3go](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9a28c/32.png) [@di3go](https://www.ruby-forum.com/u/di3go)\
**Post date:** [August 12, 2010, 3:28pm UTC](https://www.ruby-forum.com/t/fast-proxy/193179/1 "2010-08-12T15:28:48Z")

</div>

Today i have a application that send mails and this applications need to  
know when the user has opened the mail, its kind easy do this sending a  
id in some image file requested from the user  
mail(src=“[www.sample.com/image&id=1212](http://www.sample.com/image&id=1212)”).

But this need to be veryyyy fast.

Actually testing on my notebook, apache could serve some image 7000  
times a second, using em-proxy poiting to the same apache server, i  
could only get 2000 times a second, and i did nothing on em-proxy, just  
get from one side and send to another.

Have any way to this faster?

---

<div class="post-metadata">

**Author:** ![di3go](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9a28c/32.png) [@di3go](https://www.ruby-forum.com/u/di3go)\
**Post date:** [August 12, 2010, 4:26pm UTC](https://www.ruby-forum.com/t/fast-proxy/193179/2 "2010-08-12T16:26:17Z")

</div>

Diego B. wrote:

> Today i have a application that send mails and this applications need to  
> know when the user has opened the mail, its kind easy do this sending a  
> id in some image file requested from the user  
> mail(src=“[www.sample.com/image&id=1212](http://www.sample.com/image&id=1212)”).
> 
> But this need to be veryyyy fast.
> 
> Actually testing on my notebook, apache could serve some image 7000  
> times a second, using em-proxy poiting to the same apache server, i  
> could only get 2000 times a second, and i did nothing on em-proxy, just  
> get from one side and send to another.
> 
> Have any way to this faster?

forgot to say, and taking that id and inserting into redis reduce the  
performance to 1500 req/s

---

<div class="post-metadata">

**Author:** ![di3go](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9a28c/32.png) [@di3go](https://www.ruby-forum.com/u/di3go)\
**Post date:** [August 12, 2010, 5:02pm UTC](https://www.ruby-forum.com/t/fast-proxy/193179/3 "2010-08-12T17:02:36Z")

</div>

On Thu, Aug 12, 2010 at 8:26 AM, Diego B.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Actually testing on my notebook, apache could serve some image 7000  
> > times a second, using em-proxy poiting to the same apache server, i  
> > could only get 2000 times a second, and i did nothing on em-proxy, just  
> > get from one side and send to another.
> > 
> > Have any way to this faster?
> 
> forgot to say, and taking that id and inserting into redis reduce the  
> performance to 1500 req/s

One can proxy very, very fast with Ruby and EM. Fast enough that  
messing with redis will, by a long shot, be your bottleneck.

I suggest not doing it that way if you need really high speeds.

Were it me, I’d write a simple server to itself return the image, and  
I’d throw records of images served into a log. That lets you decouple  
serving the image with recording it in redis, and it makes it trivial  
to break that task up into multiple pieces, or take advantage of  
off-peak times to catch up on data loading if your peak times actually  
serves images faster than the data can be stuffed into redis.

Kirk H.

---

<div class="post-metadata">

**Author:** ![di3go](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9a28c/32.png) [@di3go](https://www.ruby-forum.com/u/di3go)\
**Post date:** [August 12, 2010, 10:41pm UTC](https://www.ruby-forum.com/t/fast-proxy/193179/4 "2010-08-12T22:41:58Z")

</div>

Kirk H. wrote:

> Were it me, I’d write a simple server to itself return the image, and  
> I’d throw records of images served into a log.

Just parse the Apache logs.

Or, if you want it more real-time, you can use the pipe log capability  
of Apache, so you can have a persistent Ruby process which receives the  
logs on stdin. But then again, you might as well just receive the HTTP  
in Ruby.

Note: you should be aware that most modern E-mail clients _don’t_ open  
remote images in E-mails, for exactly the reason that it gives away  
information about them being read (\*)

Also: if you send out one million E-mails, _and_ all of them are opened  
within a 24 hour period, _and_ 20% of the users have old clients which  
do open remote images, then you’d only have to handle an average of 2.3  
hits per second. Hardly need the world’s fastest webserver for that.

Regards, Brian.

(\*) And hence HTML E-mails with images usually now embed the images  
within the message, e.g. RFC2557, RFC2392

---

<div class="post-metadata">

**Author:** ![di3go](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9a28c/32.png) [@di3go](https://www.ruby-forum.com/u/di3go)\
**Post date:** [August 13, 2010, 4:06pm UTC](https://www.ruby-forum.com/t/fast-proxy/193179/5 "2010-08-13T16:06:39Z")

</div>

Thanks all for the help.

Thanks for the tip Kirk, im gonna parse the log, its easier and faster,  
the applications isnt real time, i have time to process the log. The log  
files gonna rotate every hour, gonna process one file per hour.

I also find something usefull, x-sendfile, i didint know that, this was  
the reason i was getting so “slow” req/s using ruby, i think using this  
with sinatra i could get near req/s as apache.

Brian,

About that, yes, its true, most mail block external images. But is the  
only way i can know if the user has read or not the mail.  
And the list is send to people who wants the mail, they trust in the  
mail content.  
Have any other way to track the mails?

Again, thanks.

Diego B.

---

<div class="post-metadata">

**Author:** ![di3go](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9a28c/32.png) [@di3go](https://www.ruby-forum.com/u/di3go)\
**Post date:** [August 13, 2010, 4:20pm UTC](https://www.ruby-forum.com/t/fast-proxy/193179/6 "2010-08-13T16:20:54Z")

</div>

Diego B. wrote:

> About that, yes, its true, most mail block external images. But is the  
> only way i can know if the user has read or not the mail.  
> And the list is send to people who wants the mail, they trust in the  
> mail content.  
> Have any other way to track the mails?

Not really. Some mailers will honour requests for return receipts, but  
they will pop up a dialog first asking the user if they’re happy to send  
it back.

The best I can think of is that you could put the content they’re  
looking for on a web page, then just E-mail them a short message with  
the link. e.g. “Click here to read this month’s newsletter”. Include a  
unique cookie in the link, e.g. as a query parameter. Then you can tell  
if they clicked through or not.

The real question is, what problem are you trying to solve by  
determining whether the user opened the mail or not?

If the problem is a commercial one (e.g. your customer wants to pay you  
based on the number of E-mails opened, not the number of E-mails  
delivered) then you could use surveys or statistical samples to estimate  
what proportion of their E-mails is opened. In other words, a bit like  
TV viewer figures.

B.

---

<div class="post-metadata">

**Author:** ![di3go](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9a28c/32.png) [@di3go](https://www.ruby-forum.com/u/di3go)\
**Post date:** [August 13, 2010, 7:07pm UTC](https://www.ruby-forum.com/t/fast-proxy/193179/7 "2010-08-13T19:07:47Z")

</div>

Brian C. wrote:

> Diego B. wrote:
> 
> > About that, yes, its true, most mail block external images. But is the  
> > only way i can know if the user has read or not the mail.  
> > And the list is send to people who wants the mail, they trust in the  
> > mail content.  
> > Have any other way to track the mails?
> 
> Not really. Some mailers will honour requests for return receipts, but  
> they will pop up a dialog first asking the user if they’re happy to send  
> it back.
> 
> The best I can think of is that you could put the content they’re  
> looking for on a web page, then just E-mail them a short message with  
> the link. e.g. “Click here to read this month’s newsletter”. Include a  
> unique cookie in the link, e.g. as a query parameter. Then you can tell  
> if they clicked through or not.
> 
> The real question is, what problem are you trying to solve by  
> determining whether the user opened the mail or not?
> 
> If the problem is a commercial one (e.g. your customer wants to pay you  
> based on the number of E-mails opened, not the number of E-mails  
> delivered) then you could use surveys or statistical samples to estimate  
> what proportion of their E-mails is opened. In other words, a bit like  
> TV viewer figures.
> 
> B.

The issue is, this system deal with marketing mail, know if the user has  
open mail is useful to my client for a lot of reasons, like, later this  
numbers turn into reports so they can discuss a new strategy and so.

And yea its a good idea to direct the user to a website using some query  
string to track.

Diego.
