<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Get Online Users in Django</title>
	<atom:link href="http://mpcabd.igeex.biz/get-online-users-in-django/feed/" rel="self" type="application/rss+xml" />
	<link>http://mpcabd.igeex.biz/get-online-users-in-django/</link>
	<description>My Technical Blog</description>
	<lastBuildDate>Sat, 10 Dec 2011 17:02:25 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: airtonix</title>
		<link>http://mpcabd.igeex.biz/get-online-users-in-django/comment-page-1/#comment-6518</link>
		<dc:creator>airtonix</dc:creator>
		<pubDate>Thu, 10 Nov 2011 22:50:10 +0000</pubDate>
		<guid isPermaLink="false">http://magicpc.wordpress.com/2009/09/22/get-online-users-in-django/#comment-6518</guid>
		<description>Any chance you could give us a peek at the source code that demonstrates your approach to this scenario?</description>
		<content:encoded><![CDATA[<p>Any chance you could give us a peek at the source code that demonstrates your approach to this scenario?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jafte</title>
		<link>http://mpcabd.igeex.biz/get-online-users-in-django/comment-page-1/#comment-6250</link>
		<dc:creator>Jafte</dc:creator>
		<pubDate>Mon, 10 Oct 2011 10:02:16 +0000</pubDate>
		<guid isPermaLink="false">http://magicpc.wordpress.com/2009/09/22/get-online-users-in-django/#comment-6250</guid>
		<description>made little update, now i can check users status:

from django.db import models
from django.contrib.auth.models import User
from datetime import datetime, timedelta

class UserActivity(models.Model):
    last_activity_ip = models.IPAddressField()
    last_activity_date = models.DateTimeField(default = datetime(1941, 1, 1))
    user = models.OneToOneField(User, primary_key=True)

    def is_online(self):
        no_active_delta = datetime.now() - self.last_activity_date
        if no_active_delta &gt; timedelta(minutes=21):
            return False
        else:
            return True</description>
		<content:encoded><![CDATA[<p>made little update, now i can check users status:</p>
<p>from django.db import models<br />
from django.contrib.auth.models import User<br />
from datetime import datetime, timedelta</p>
<p>class UserActivity(models.Model):<br />
    last_activity_ip = models.IPAddressField()<br />
    last_activity_date = models.DateTimeField(default = datetime(1941, 1, 1))<br />
    user = models.OneToOneField(User, primary_key=True)</p>
<p>    def is_online(self):<br />
        no_active_delta = datetime.now() &#8211; self.last_activity_date<br />
        if no_active_delta &gt; timedelta(minutes=21):<br />
            return False<br />
        else:<br />
            return True</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rencontre</title>
		<link>http://mpcabd.igeex.biz/get-online-users-in-django/comment-page-1/#comment-5511</link>
		<dc:creator>Rencontre</dc:creator>
		<pubDate>Tue, 26 Jul 2011 15:17:56 +0000</pubDate>
		<guid isPermaLink="false">http://magicpc.wordpress.com/2009/09/22/get-online-users-in-django/#comment-5511</guid>
		<description>Hi Abd Allah,
I forgot to tell that my app actually combines this with a middleware, so you can disable the behaviour just by removing the middleware from the list.
The only (slight) problem is in the login view : each user login hits the cache, even when the middleware is off. The performance cost is very minimal so it&#039;s just a matter of just enabling or disabling the middleware.
It would be a perfect solution if the custom login function could tell if the middleware is active.</description>
		<content:encoded><![CDATA[<p>Hi Abd Allah,<br />
I forgot to tell that my app actually combines this with a middleware, so you can disable the behaviour just by removing the middleware from the list.<br />
The only (slight) problem is in the login view : each user login hits the cache, even when the middleware is off. The performance cost is very minimal so it&#8217;s just a matter of just enabling or disabling the middleware.<br />
It would be a perfect solution if the custom login function could tell if the middleware is active.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Abd Allah Diab</title>
		<link>http://mpcabd.igeex.biz/get-online-users-in-django/comment-page-1/#comment-5510</link>
		<dc:creator>Abd Allah Diab</dc:creator>
		<pubDate>Tue, 26 Jul 2011 13:53:07 +0000</pubDate>
		<guid isPermaLink="false">http://magicpc.wordpress.com/2009/09/22/get-online-users-in-django/#comment-5510</guid>
		<description>Yeah that&#039;s right, the solution I introduced uses the database every time, your solution is better since it uses the memcache.
But I created a middleware so I can be able to update the last activity date on every request which is less complex than updating the state on every page view. I mean in your solution you&#039;ll have to update the status manually every time on every page call, while in mine you won&#039;t have to do that manually. Also when you decide for example to disable this logic or remove it, in your case you&#039;ll have to edit many methods and page calls, while in my solution all you have to do is to disable the middleware.

So I think that the best solution we can come up with is to merge your memcache method with my middleware :)

Thanks.</description>
		<content:encoded><![CDATA[<p>Yeah that&#8217;s right, the solution I introduced uses the database every time, your solution is better since it uses the memcache.<br />
But I created a middleware so I can be able to update the last activity date on every request which is less complex than updating the state on every page view. I mean in your solution you&#8217;ll have to update the status manually every time on every page call, while in mine you won&#8217;t have to do that manually. Also when you decide for example to disable this logic or remove it, in your case you&#8217;ll have to edit many methods and page calls, while in my solution all you have to do is to disable the middleware.</p>
<p>So I think that the best solution we can come up with is to merge your memcache method with my middleware <img src='http://mpcabd.igeex.biz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rencontre</title>
		<link>http://mpcabd.igeex.biz/get-online-users-in-django/comment-page-1/#comment-5509</link>
		<dc:creator>Rencontre</dc:creator>
		<pubDate>Tue, 26 Jul 2011 11:52:08 +0000</pubDate>
		<guid isPermaLink="false">http://magicpc.wordpress.com/2009/09/22/get-online-users-in-django/#comment-5509</guid>
		<description>Hi,
I&#039;ve been looking for solutions before to know which users were online.
At first I looked at your technique but I found that using a new model for the activity and using a middleware to actually hit the database (write operation) costs too much.
Then I used a technique using an access log. To find the online users, you query the access log and group access entries by user.
The query in this case is quite slow but you don&#039;t have to add another middleware just to update the last activity.

I&#039;ve actually found a better technique which is fast and does not hit the database, also you do not need an access log.
You create memcached entries to know if a user is online.
Everytime a user logs in, you update another entry in the cache which holds a list of online users (this list can be up to 1MB long, the max size of a memcached entry). Whenever you need the list of online users, you remove offline users from the list and return the resulting list.
Every page view, you can update the user online status in the cache. If the status goes from offline to online, you add the user to the online list.
It&#039;s a bit unclear but preserves the app from database hits.</description>
		<content:encoded><![CDATA[<p>Hi,<br />
I&#8217;ve been looking for solutions before to know which users were online.<br />
At first I looked at your technique but I found that using a new model for the activity and using a middleware to actually hit the database (write operation) costs too much.<br />
Then I used a technique using an access log. To find the online users, you query the access log and group access entries by user.<br />
The query in this case is quite slow but you don&#8217;t have to add another middleware just to update the last activity.</p>
<p>I&#8217;ve actually found a better technique which is fast and does not hit the database, also you do not need an access log.<br />
You create memcached entries to know if a user is online.<br />
Everytime a user logs in, you update another entry in the cache which holds a list of online users (this list can be up to 1MB long, the max size of a memcached entry). Whenever you need the list of online users, you remove offline users from the list and return the resulting list.<br />
Every page view, you can update the user online status in the cache. If the status goes from offline to online, you add the user to the online list.<br />
It&#8217;s a bit unclear but preserves the app from database hits.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Abd Allah Diab</title>
		<link>http://mpcabd.igeex.biz/get-online-users-in-django/comment-page-1/#comment-18</link>
		<dc:creator>Abd Allah Diab</dc:creator>
		<pubDate>Sat, 21 Nov 2009 16:35:21 +0000</pubDate>
		<guid isPermaLink="false">http://magicpc.wordpress.com/2009/09/22/get-online-users-in-django/#comment-18</guid>
		<description>Thanks Sam for coming by, that is my pleasure :)</description>
		<content:encoded><![CDATA[<p>Thanks Sam for coming by, that is my pleasure <img src='http://mpcabd.igeex.biz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sam</title>
		<link>http://mpcabd.igeex.biz/get-online-users-in-django/comment-page-1/#comment-17</link>
		<dc:creator>Sam</dc:creator>
		<pubDate>Sat, 21 Nov 2009 13:12:55 +0000</pubDate>
		<guid isPermaLink="false">http://magicpc.wordpress.com/2009/09/22/get-online-users-in-django/#comment-17</guid>
		<description>Thanks for taking out time &amp; putting in the effort to make this available to all as a generic solution.

This is what makes the Django/Python community so great :)</description>
		<content:encoded><![CDATA[<p>Thanks for taking out time &amp; putting in the effort to make this available to all as a generic solution.</p>
<p>This is what makes the Django/Python community so great <img src='http://mpcabd.igeex.biz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>

