Curious: How is this accomplished?

Discussion in 'PHP' started by Optimus Crime, Dec 30, 2006.

  1. #1
    I was just wondering. If one were to provide a basic free counter service (no tracking, etc.) - something like digits.com minus the paid option, what will be the kind of bandwidth required to cater about a million visitors?

    And, this Tim Boutell's GD library. Is that to reduce the bandwidth or to speed up the process in the server?

    Stan.
     
    Optimus Crime, Dec 30, 2006 IP
  2. B.V.E.

    B.V.E. Peon

    Messages:
    106
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Just take a look at the size of some images provided by those free counter services: an image size between 1 and 2KB is probably reasonable, so that would be at least somewhere between 1 and 2GB for a million visitors.
     
    B.V.E., Dec 31, 2006 IP
  3. Nikolas

    Nikolas Well-Known Member

    Messages:
    1,022
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    150
    #3
    And BTW the GD library is not that good for high traffic apps, as it uses a lot of memory. The imagemagick library is much better, but it is more difficult to use.
     
    Nikolas, Dec 31, 2006 IP
  4. Optimus Crime

    Optimus Crime Well-Known Member

    Messages:
    648
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    110
    #4
    No, that will be for a million requests. A million users having an average of 1000 hits a month, if each image is only 2 KB, 2000 GB per month bandwidth.

    But, isn't that too high?

    So, they do it like this only, and not any other technique which might reduce the bandwidth to say 100 MB per month?
     
    Optimus Crime, Dec 31, 2006 IP
  5. Optimus Crime

    Optimus Crime Well-Known Member

    Messages:
    648
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    110
    #5
    Correction: 100 GB per month.

    (sorry can't edit posts on Palm)
     
    Optimus Crime, Dec 31, 2006 IP
  6. GeorgeB.

    GeorgeB. Notable Member

    Messages:
    5,695
    Likes Received:
    288
    Best Answers:
    0
    Trophy Points:
    280
    #6
    You also need a good server that can handle the load and MySQL queries.

    In fact if you're serious about the traffic levels you plan to support I'd suggest a dual server solution with one web and one database server.
     
    GeorgeB., Dec 31, 2006 IP
  7. Optimus Crime

    Optimus Crime Well-Known Member

    Messages:
    648
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    110
    #7
    Okay. But apart from all the secondary issues, is there a way to reduce the bandwidth per se? That is, for one visit, instead of say 2 KB, something like 1/10th of a KB?
     
    Optimus Crime, Dec 31, 2006 IP
  8. kajakske

    kajakske Well-Known Member

    Messages:
    139
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    165
    #8
    Depending on what image you want to show, I could fit 7 digits into a 50 x 12 pixels image saved as a GIF with 2 colors for a total of 112 bytes.
     
    kajakske, Jan 1, 2007 IP
  9. Optimus Crime

    Optimus Crime Well-Known Member

    Messages:
    648
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    110
    #9
    kajakske, that is cool. Using PHP? So, if I have a script like CounterCode, you would be able to modify it and do it like that?

    Like the counter on this page? fridayharborirish.com

    Thnks,
    Stan.
     
    Optimus Crime, Jan 1, 2007 IP
  10. kajakske

    kajakske Well-Known Member

    Messages:
    139
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    165
    #10
    The counter on that site is 400 bytes, which isn't that bad considering the size is bigger than the one I tested with.


    Some key points to keep in mind:

    When you save your image as a GIF, keep it to 2 colors. This is because GIF images save the palette of colors they use inside the image. 2 colors = smallest you can go (transparent is considered a color too).

    Keep it as small as possible. (width / height I mean).
    If your counter fits in an image 60 x 12 pixels, it will be smaller than the same counter using a bigger fontsize in a 80 x 14 image for example (hence why your example is somewhat bigger than my test).


    Wheter you make the image with PHP's GD library or any other one will not have any impact on the bandwith they will be using (as long as they are saved optimally).


    If you really insist on a better looking counter, say a JPEG with a small logo and then the numbers, you will have a considerable amount of increased bandwith compaired to a small GIF one ...
     
    kajakske, Jan 1, 2007 IP
  11. Optimus Crime

    Optimus Crime Well-Known Member

    Messages:
    648
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    110
    #11
    Thanks kajakske,

    Let us say I offer many choices for the user to pick. Like digits.com/thumbnail/

    And, on average a visitor picks a Interlaced GIF with width 300 px and height 30 px. But, this average size is 5 KB as on that site. Try, for example, digits.com/thumbnail/wc-06-3.gif

    That makes it a 5TB in bandwidth for a million visitors averaging 1000 hits a month. Is there a way to get the same quality of image with a lesser size, like a 1 KB?
     
    Optimus Crime, Jan 1, 2007 IP
  12. kajakske

    kajakske Well-Known Member

    Messages:
    139
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    165
    #12
    Defenetly !

    The example you gave me is a GIF with 256 colors in its palette ...
    Saving the same image as a JPG with 30% quality could save you 50% bandwith.

    http://www.hawkfield.be/temp/wc-06-3.jpg

    I just opened your image and saved it as a JPG in Photoshop, but you can do the same in PHP with the imagejpeg() function (the third parameter is the quality).


    Basically (not always, you have to test) an image with very little colors is smaller in GIF format, an image with alot of colors is smaller in JPG ...
     
    kajakske, Jan 1, 2007 IP
  13. Optimus Crime

    Optimus Crime Well-Known Member

    Messages:
    648
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    110
    #13
    Well, I get that logic, but I am zero in programming. I just want to know if all this creation and compression (jpeg or reduced colors gif) can be done on the fly so fast as to serve, say, maybe 50 users in one second?

    Thanks,
    Stan.
     
    Optimus Crime, Jan 1, 2007 IP
  14. kajakske

    kajakske Well-Known Member

    Messages:
    139
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    165
    #14
    Hmm, I have absolutly no idea :-(

    The GD library isn't that fast I heard, but I wouldn't be able to tell you...

    How is the file created now ?
    If it is a static GIF (like the one you showed me) it can just be optimised once with PhotoShop.
     
    kajakske, Jan 2, 2007 IP
  15. Optimus Crime

    Optimus Crime Well-Known Member

    Messages:
    648
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    110
    #15
    As in image creation on the fly for the counter?
     
    Optimus Crime, Jan 2, 2007 IP
  16. INTEMPO

    INTEMPO Active Member

    Messages:
    64
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #16
    ImageMagick is not difficult to use at all. Just look through imagemagick . com and you'll understand it. And if you need to process a lot of graphical operations for high traffic you really can't do it without ImageMagick. And when you'll be choosing a hosting for your site check the ImageMagick availability there, because it's necessary. :cool:

    Regards, Denis
     
    INTEMPO, Jan 2, 2007 IP