I am thinking about how to build advertise site which works like twitter.开发者_开发百科
That means, most user don't not visit the site by browser, they should run a dedicated client application on their PC or smart phone. Then they set some filters about what kind of advertise they like. And when new post that fulfill their needs appear, the client will make a notification.
To make that client as real time as possible, it has to poll the server within a short time interval.The problem is, should I do the filtering at the server side when client polls, or should I simply transfer all new posts to client and let client do the filtering?
Making server side filtering might cause too much CPU cycles of server, but transferring every post blindly to client might waste a lot of bandwidth.
Just a brain game. :)
Filtering data on server side my applying a simple filter query on it (SELECT * FROM tweets WHERE category IN (1,2,3,4,5,)
) won't cost you much in performance - much less than distributing all available data to all clients anyway.
If by filtering you mean an SQL query, then making it on the server will be better of course. Inquiring from any SQL database is very light even if you make thousands of SELECTs.
As others have pointed out, there is no point in sending data which isn't going to be used. People only want to download what they can use. If someone pays for their mobile data allowance and your app shows them 2 ads and uses up 1000 ads of data they will stop using your service.
You can filter by certain types at the database side, or you can filter by some more indepth business logic in the service before the final data is sent back to the client.
The main point is; low data transfer, quicker responses, happier user :-)
Oh, especially if you're also considering deployment onto mobile devices, /always/ filter on the server side. Maybe the main issue is finding appropriate data structures of linking new postings to the filters so that isn't expensive. And you can also keep the most-asked-for entries and filters in memcached so you don't hit the database always.
There is absolutely no sense at all to transfer all the stuff to the client,and then not show it.
i think filtering on the server would be the much better way it will reduce the amount of data transfered (expecially for smart phone users this will be a huge gain)
精彩评论