scalable server
Anne Ogborn <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
A little while back a new prolog programmer wanted to experiment with prolog web servers.
After a bit they had something they wanted to serve, so I accomodated them on my own
server. No problem, have them run on a high port and I'll have apache do the reverse proxy.
OOops!
somehow I managed to misconfigure this and turn on an open proxy. Apache admin is NOT my strong suite.
Of course after a week or so some ad place in china discovers this an starts directing a huge
volume of traffic towards my little server.
My first instinct of course is to block it off. Then the lightbulb goes on in my head.
these requests aren't from the spammer, they're from ordinary users who are viewing pages
with the spammers ads.
I quickly put on my thinking hat and realize that having lots of people include your content in their
web pages isn't necessarily a bad thing. I spend a couple seconds thinking about what I'd like to say
to lots and lots of people... and start writing prolog.
This stays up for about 20 seconds, then starts yelling about too many open files.
Not sure why it's opening all these files?
My first attempt doesn't do anything with threads, so I follow the example about scaling on the site
and give it lots of threads. Same result.
I was serving an image at first - I remove that. Still same thing.
Apache actually will serve all this stuff - any idea why the prolog server won't?
I've never had a server that attracted much attention - it's sorta interesting. I'd like to take the advantage
of the free load testing to learn.
% load the multi-threaded http server
:- use_module(library(http/thread_httpd)).
% and the standard handler dispatcher
:- use_module(library(http/http_dispatch)).
:- use_module(library(http/html_write)).
:- use_module(library(thread_pool)).
:- thread_pool_create(media, 200, []).
start :-
http_server(http_dispatch, [port(80)]).
:- http_handler('/tnsf.png', send_file, [spawn(media), priority(10)]).
:- http_handler(/, holder, [prefix]).
send_file(Request) :-
http_reply_file('tnsf.png', [cache(true)], Request).
holder(_Request) :-
reply_html_page(title('Transsexual Rights'),
div(p('Please support transsexual women\'s basic human right to live our lives.'))
).