Thanks.Yes understood the flaw in my approach

On Thu, Dec 15, 2011 at 12:15 AM, Alec Taylor <alec.tayl...@gmail.com>wrote:

> No reason you can't ACID the whole thing
>
> Important info: http://en.wikipedia.org/wiki/Concurrency_control#Methods
>
> On Thu, Dec 15, 2011 at 5:18 AM, akaariai <akaar...@gmail.com> wrote:
> > A quick warning about your approach: if you use that in multi-threaded
> > environment, you are toasted. You will get two concurrent users for
> > the same connection, and that will not work nicely. For example
> > transaction control will be broken. That is also the reason why that
> > sort of thing is not used in Django.
> >
> > As for connection pooling, there is a patch (ticket 17258) which is
> > somewhat likely to get in that should allow much easier creation of
> > connection pools by external projects.
> >
> >  - Anssi
> >
> > On Dec 14, 1:33 pm, nipunreddevil <nipunredde...@gmail.com> wrote:
> >> Hi,
> >>
> >> I have gone similar threads likehttp://
> stackoverflow.com/questions/1125504/django-persistent-database...
> >> and other stuff on same topic. However Django doesn't officially
> >> support persistent connections to MySQL and Mongo(to my limited
> >> knowledge).So i tried avoiding a lot of stuff and tried to make it
> >> simple.So what i did was in my views.py made global connection
> >> variables for both MongoDB and MySQL,something like:
> >>
> >> from pymongo import Connection
> >> import MySQLdb
> >> global
> >> mongo_connection,mongo_db,collection,mysql_connection,mysql_cursor
> >> mysql_connection = MySQLdb.connect (host = "localhost",
> >>                        user = "root",
> >>                        passwd = "password",
> >>                        db = "demo")
> >> mysql_cursor = mysql_connection.cursor ()
> >> mongo_connection = Connection()
> >> mongo_db = mongo_connection.test_database
> >> collection = mongo_db.test_collection
> >> So after this when the required view is called as per URL requested,i
> >> dump the data in the two databases.Like:
> >>
> >> mysql_cursor.execute('''INSERT INTO
> >> table_name(l,n_n,n_id,s_n,s_id,u,r) VALUES
> >> (%s,%s,%s,%s,%s,%s,%s)''',
> >> (l,n_n,n_id,s_name,s_id,u,re)
> >> )
> >> And similarly i did for saving to MongoDB.
> >>
> >> Obviously there's this flaw in this approach that i am not closing the
> >> connection anywhere.But this approach does seem to work and work well.
> >>
> >> Why is this sort of approach not used?
> >>
> >> How can i measure the performance improvements i get by using this
> >> approach v/s letting Django create a new connection to DB on each
> >> call.
> >>
> >> Also a batch insert is supposed to make things even better,by reducing
> >> calls to DB.How can such a concept be implemented within view
> >> definition?
> >>
> >> Here is how my application behaved before i had used my method of
> >> trying to make a persistent connection and had let Django take care of
> >> it
> >>
> >> mysql> show status like '%onn%';
> >> +--------------------------+--------+
> >> | Variable_name            | Value  |
> >> +--------------------------+--------+
> >> | Aborted_connects         | 0      |
> >> | Connections              | 164359 |
> >> | Max_used_connections     | 3      |
> >> | Ssl_client_connects      | 0      |
> >> | Ssl_connect_renegotiates | 0      |
> >> | Ssl_finished_connects    | 0      |
> >> | Threads_connected        | 1      |
> >> +--------------------------+--------+
> >> 7 rows in set (0.00 sec)
> >> After a few seconds when i ran the same query i got:
> >>
> >> mysql> show status like '%onn%';
> >> +--------------------------+--------+
> >> | Variable_name            | Value  |
> >> +--------------------------+--------+
> >> | Aborted_connects         | 0      |
> >> | Connections              | 175047 |
> >> | Max_used_connections     | 3      |
> >> | Ssl_client_connects      | 0      |
> >> | Ssl_connect_renegotiates | 0      |
> >> | Ssl_finished_connects    | 0      |
> >> | Threads_connected        | 1      |
> >> +--------------------------+--------+
> >> 7 rows in set (0.00 sec)
> >> However after using my approach the number of connections didn't
> >> increase.
> >>
> >> NB:I have posted same post onhttp://
> stackoverflow.com/questions/8502814/django-persistent-db-conne...
> >> but thought this might be a good place to get the answer
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to