Saturday, January 18, 2014

comp.lang.python - 26 new messages in 8 topics - digest

comp.lang.python
http://groups.google.com/group/comp.lang.python?hl=en

comp.lang.python@googlegroups.com

Today's topics:

* How to write this as a list comprehension? - 7 messages, 6 authors
http://groups.google.com/group/comp.lang.python/t/0b63055a0d321622?hl=en
* setup.py issue - some files are included as intended, but one is not - 1
messages, 1 author
http://groups.google.com/group/comp.lang.python/t/615fb6822e01f928?hl=en
* Python 3.x adoption - 4 messages, 3 authors
http://groups.google.com/group/comp.lang.python/t/3d5defc6634ef3b4?hl=en
* numpy.where() and multiple comparisons - 4 messages, 3 authors
http://groups.google.com/group/comp.lang.python/t/252e25bda74254c2?hl=en
* Python Scalability TCP Server + Background Game - 6 messages, 4 authors
http://groups.google.com/group/comp.lang.python/t/8234bf03949a8164?hl=en
* doctests compatibility for python 2 & python 3 - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/e83b94c8f7e04717?hl=en
* Guessing the encoding from a BOM - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/1b4501ed3e9e2af1?hl=en
* python to enable javascript , tried selinium, ghost, pyQt4 already - 1
messages, 1 author
http://groups.google.com/group/comp.lang.python/t/a453f34131ad9343?hl=en

==============================================================================
TOPIC: How to write this as a list comprehension?
http://groups.google.com/group/comp.lang.python/t/0b63055a0d321622?hl=en
==============================================================================

== 1 of 7 ==
Date: Fri, Jan 17 2014 3:19 pm
From: Piet van Oostrum


Hi,

I am looking for an elegant way to write the following code as a list
comprehension:

labels = []
for then, name in mylist:
_, mn, dy, _, _, _, wd, _, _ = localtime(then)
labels.append(somefunc(mn, day, wd, name))

So mylist is a list of tuples, the first member of the tuple is a time
(as epoch offset) and I neeed to apply a function on some fields of the
localtime of it.

I could define a auxiliary function like:

def auxfunc(then, name):
_, mn, dy, _, _, _, wd, _, _ = localtime(then)
return somefunc(mn, day, wd, name)

and then use
[auxfunc(then, name) for then, name in mylist]

or even
[auxfunc(*tup) for tup in mylist]

But defining the auxfunc takes away the elegance of a list comprehension. I would like to integrate the unpacking of localtime() and calling somefunc within the list comprehension, but I don't see a simple way to do that.

somefunc(mn, day, wd, name) for _, mn, dy, _, _, _, wd, _, _ in [localtime(then)]
(i.e. using a list comprehension on a one element list to do the variable shuffling)
works but I don't find that very elegant.

labels = [somefunc(mn, day, wd, name)
for then, name in mylist
for _, mn, dy, _, _, _, wd, _, _ in [localtime(then)]]

Python misses a 'where' or 'let'-like construction as in Haskell.

Anybody has a more elegant solution?
--
Piet van Oostrum <piet@vanoostrum.org>
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]




== 2 of 7 ==
Date: Fri, Jan 17 2014 3:49 pm
From: Dan Stromberg


On Fri, Jan 17, 2014 at 3:19 PM, Piet van Oostrum <piet@vanoostrum.org> wrote:
> Hi,
>
> I am looking for an elegant way to write the following code as a list
> comprehension:
>
> labels = []
> for then, name in mylist:
> _, mn, dy, _, _, _, wd, _, _ = localtime(then)
> labels.append(somefunc(mn, day, wd, name))

My recomendation: Don't use a list comprehension. List comprehensions
and generator expressions are great for quick little things, but
become less readable when you have to string them over multiple
physical lines.

> labels = [somefunc(mn, day, wd, name)
> for then, name in mylist
> for _, mn, dy, _, _, _, wd, _, _ in [localtime(then)]]




== 3 of 7 ==
Date: Fri, Jan 17 2014 7:25 pm
From: Rustom Mody


On Saturday, January 18, 2014 4:49:55 AM UTC+5:30, Piet van Oostrum wrote:
> Hi,

> I am looking for an elegant way to write the following code as a list
> comprehension:

> labels = []
> for then, name in mylist:
> _, mn, dy, _, _, _, wd, _, _ = localtime(then)
> labels.append(somefunc(mn, day, wd, name))

> So mylist is a list of tuples, the first member of the tuple is a time
> (as epoch offset) and I neeed to apply a function on some fields of the
> localtime of it.

> I could define a auxiliary function like:

> def auxfunc(then, name):
> _, mn, dy, _, _, _, wd, _, _ = localtime(then)
> return somefunc(mn, day, wd, name)

> and then use
> [auxfunc(then, name) for then, name in mylist]

> or even
> [auxfunc(*tup) for tup in mylist]

> But defining the auxfunc takes away the elegance of a list comprehension. I would like to integrate the unpacking of localtime() and calling somefunc within the list comprehension, but I don't see a simple way to do that.

> somefunc(mn, day, wd, name) for _, mn, dy, _, _, _, wd, _, _ in [localtime(then)]
> (i.e. using a list comprehension on a one element list to do the variable shuffling)
> works but I don't find that very elegant.

> labels = [somefunc(mn, day, wd, name)
> for then, name in mylist
> for _, mn, dy, _, _, _, wd, _, _ in [localtime(then)]]

> Python misses a 'where' or 'let'-like construction as in Haskell.

+1
Yes Ive often been bitten by the lack of a 'comprehension-let'

Something like this is possible??


[somefunc(mn,day,wd,name) for (_, mn,dy,_,_,_,wd,_,_), name) in [localtime(then), name for then, name in mylist]]

Some debugging of the structure will be necessary (if at all possible)
I dont have your functions so cant do it






== 4 of 7 ==
Date: Sat, Jan 18 2014 12:36 am
From: Peter Otten <__peter__@web.de>


Piet van Oostrum wrote:

> Hi,
>
> I am looking for an elegant way to write the following code as a list
> comprehension:
>
> labels = []
> for then, name in mylist:
> _, mn, dy, _, _, _, wd, _, _ = localtime(then)
> labels.append(somefunc(mn, day, wd, name))
>
> So mylist is a list of tuples, the first member of the tuple is a time
> (as epoch offset) and I neeed to apply a function on some fields of the
> localtime of it.
>
> I could define a auxiliary function like:
>
> def auxfunc(then, name):
> _, mn, dy, _, _, _, wd, _, _ = localtime(then)
> return somefunc(mn, day, wd, name)
>
> and then use
> [auxfunc(then, name) for then, name in mylist]
>
> or even
> [auxfunc(*tup) for tup in mylist]
>
> But defining the auxfunc takes away the elegance of a list comprehension.
> I would like to integrate the unpacking of localtime() and calling
> somefunc within the list comprehension, but I don't see a simple way to do
> that.
>
> somefunc(mn, day, wd, name) for _, mn, dy, _, _, _, wd, _, _ in
> [localtime(then)] (i.e. using a list comprehension on a one element list
> to do the variable shuffling) works but I don't find that very elegant.
>
> labels = [somefunc(mn, day, wd, name)
> for then, name in mylist
> for _, mn, dy, _, _, _, wd, _, _ in [localtime(then)]]
>
> Python misses a 'where' or 'let'-like construction as in Haskell.
>
> Anybody has a more elegant solution?

Options I can think of:

You could do it in two steps...

time_name_pairs = ((localtime(then), name) for then, name in mylist)
labels = [somefunc(t.tm_mon, t.tm_mday, t.tm_wday, name)
for t, name in time_name_pairs]

...or you could inline the helper function...

mon_mday_wday = operator.attrgetter("tm_mon", "tm_day", "tm_wday")
labels = [somefunc(*mon_mday_wday(localtime(then)), name=name)
for then, name in mylist]

-- but both seem less readable than the classical for-loop.

What would a list-comp with `let` or `where` look like? Would it win the
beauty contest against the loop?





== 5 of 7 ==
Date: Sat, Jan 18 2014 2:00 am
From: Piet van Oostrum


Rustom Mody <rustompmody@gmail.com> writes:

> On Saturday, January 18, 2014 4:49:55 AM UTC+5:30, Piet van Oostrum wrote:
[...]
>
>> Python misses a 'where' or 'let'-like construction as in Haskell.
>
> +1
> Yes Ive often been bitten by the lack of a 'comprehension-let'

If it used only in a comprehension as in my example you can write instead of 'where vars = expr':
for vars in [expr], unnecessarily construction a one element list.
If there would be a syntax like:
for vars = expr
this could be avoided.
>
> Something like this is possible??
>
>
> [somefunc(mn,day,wd,name) for (_, mn,dy,_,_,_,wd,_,_), name) in
> [localtime(then), name for then, name in mylist]]
It works modulo some corrections in the parentheses:

[somefunc(mn,day,wd,name) for (_, mn,dy,_,_,_,wd,_,_), name in
[(localtime(then), name) for then, name in mylist]]
but I find that hardly more elegant.
--
Piet van Oostrum <piet@vanoostrum.org>
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]




== 6 of 7 ==
Date: Sat, Jan 18 2014 2:57 am
From: matej@ceplovi.cz (Matěj Cepl)


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 2014-01-17, 23:19 GMT, you wrote:
> But defining the auxfunc takes away the elegance of a list
> comprehension.

Au contraire! Remember, that brevity is the sister of talent.

I would definitively vote for

labels = [make_label(then, name) for then, name in mylist]

(always use descriptive names of functions and variables;
auxfunc is a short way to the hell)

Beauty of the list comprehensions is that they show nicely what
list is being processed, how it is filtered (if at all), and
what we do with each element of the generated list. Anything you
add to this simplicity is wrong. Whenever you start to feel you
are missing some methods how to stuff more commands into
a comprehension (or for example multiple embedded ones), you
should start new function.

The same rule applies here as with any other lambda function
(because these are in fact lambda functions): the best way how
to write lambda is to write algorithm somewhere on the side,
describe what this function does in one word, then add `def` in
front of that name, and use so created named function instead.

Best,

Matěj

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (GNU/Linux)

iD8DBQFS2l4X4J/vJdlkhKwRAjEgAJ4n1OuANYlVFzlgBZ0f1uMhO/t36gCfdFjE
VmYDJ+F7aN0khzvlY50i0iA=
=Trcc
-----END PGP SIGNATURE-----




== 7 of 7 ==
Date: Sat, Jan 18 2014 3:53 am
From: Alain Ketterlin


Piet van Oostrum <piet@vanoostrum.org> writes:

[...]
> I could define a auxiliary function like:
>
> def auxfunc(then, name):
> _, mn, dy, _, _, _, wd, _, _ = localtime(then)
> return somefunc(mn, day, wd, name)
>
> and then use
> [auxfunc(then, name) for then, name in mylist]

[...]

> labels = [somefunc(mn, day, wd, name)
> for then, name in mylist
> for _, mn, dy, _, _, _, wd, _, _ in [localtime(then)]]
>
> Python misses a 'where' or 'let'-like construction as in Haskell.

"let x = v in e" really is (lambda x:e)(v)

In your case:

[ (lambda na,ti : somefunc(ti[1],ti[2],ti[6],na))(name,localtime(then))
for then,name in mylist ]

Warning: absolutely untested (not even syntax-checked).

You may also use *localtime(...) and keep underscores.

-- Alain.





==============================================================================
TOPIC: setup.py issue - some files are included as intended, but one is not
http://groups.google.com/group/comp.lang.python/t/615fb6822e01f928?hl=en
==============================================================================

== 1 of 1 ==
Date: Fri, Jan 17 2014 4:43 pm
From: Dan Stromberg


On Wed, Jan 15, 2014 at 7:18 AM, Piet van Oostrum <piet@vanoostrum.org> wrote:
> Dan Stromberg <drsalists@gmail.com> writes:
>
>> On Sat, Jan 11, 2014 at 2:04 PM, Dan Stromberg <drsalists@gmail.com> wrote:
>>> Hi folks.
>>>
>>> I have a setup.py problem that's driving me nuts.
>>
>> Anyone? I've received 0 responses.
>
> I can't even install your code because there's a bug in it.
>
> m4_treap.m4 contains this instruction twice:
>
> ifdef(/*pyx*/,cp)if current is None:
> ifdef(/*pyx*/,cp)raise KeyError
>
> Which when generating pyx_treap.pyx (with *pyx* defined) expands to the syntactically incorrect
>
> cpif current is None:
> cpraise KeyError
Apologies. I'd fixed that in my source tree, but not checked it in.

It's checked in now.





==============================================================================
TOPIC: Python 3.x adoption
http://groups.google.com/group/comp.lang.python/t/3d5defc6634ef3b4?hl=en
==============================================================================

== 1 of 4 ==
Date: Fri, Jan 17 2014 5:01 pm
From: Dennis Lee Bieber


On Fri, 17 Jan 2014 18:03:45 -0500, Terry Reedy <tjreedy@udel.edu>
declaimed the following:


>Not mentioned in the wiki article is the change in calling convention
>from call by value to call by reference (or maybe the opposite). I
>remember a program crashing because of this when I tried it with F77.
>
Maybe because there was NO change in calling convention. FORTRAN was
call by reference in all versions I've worked with. DEC did add special
"functions" to force a parameter to be passed as "value", "reference", or
"descriptor" -- mostly to interface with other languages (descriptor is
what was used for character strings -- basically a structure containing the
length of the string/buffer, and the address of said buffer).

However, one may have encountered an implementation that did some
checking for duplicated parameter addresses -- or may have behaved
internally as a value/return system, wherein the by-reference parameters
were copied to local/stack storage, manipulated, and only written back to
the reference address on exit. That would result in differences:

a = 1
call xyz(a, b, a)

subroutine xyz(x, y, z)

x = x + 1
z = z * 2

...
In a true by-reference system, "a" would turn into 2 for the first
assignment, but then turn into 4 after the second.

In value/return, the second assignment still sees "1" and results in
"2", and thereby "a" becomes "2", not "4"...

I'd still consider a value/return scheme to be a misbehaving FORTRAN.
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/





== 2 of 4 ==
Date: Fri, Jan 17 2014 5:18 pm
From: Ben Finney


Terry Reedy <tjreedy@udel.edu> writes:

> Since 3.0, we have added new syntax ('yield from', u'' for instance)
> but I do not believe we have deleted or changed any syntax (I might
> have forgotten something minor)

I'm aware of the removal of '`foo`' (use 'repr(foo)' instead), and
removal of 'except ExcClass, exc_instance' (use 'except ExcClass as
exc_instance' instead).

--
\ "For my birthday I got a humidifier and a de-humidifier. I put |
`\ them in the same room and let them fight it out." —Steven Wright |
_o__) |
Ben Finney





== 3 of 4 ==
Date: Fri, Jan 17 2014 5:27 pm
From: Ben Finney


Ben Finney <ben+python@benfinney.id.au> writes:

> Terry Reedy <tjreedy@udel.edu> writes:
>
> > Since 3.0, we have added new syntax ('yield from', u'' for instance)
> > but I do not believe we have deleted or changed any syntax (I might
> > have forgotten something minor)
>
> I'm aware of the removal of '`foo`' (use 'repr(foo)' instead), and
> removal of 'except ExcClass, exc_instance' (use 'except ExcClass as
> exc_instance' instead).

Ah, you meant "deleted or changed any Python 3 syntax". No, I'm not
aware of any such changes.

--
\ "I have never imputed to Nature a purpose or a goal, or |
`\ anything that could be understood as anthropomorphic." —Albert |
_o__) Einstein, unsent letter, 1955 |
Ben Finney





== 4 of 4 ==
Date: Fri, Jan 17 2014 6:49 pm
From: Roy Smith


In article <lbc296$itl$1@reader1.panix.com>,
Grant Edwards <invalid@invalid.invalid> wrote:

> On 2014-01-17, Tim Chase <python.list@tim.thechases.com> wrote:
> > On 2014-01-17 15:27, Grant Edwards wrote:
> >> > What's wrong?...
> >>
> >> Python 2.7 still does everything 99% of us need to do, and we're too
> >> lazy to switch.
> >
> > And in most distros, typing "python" invokes 2.x, and explicitly
> > typing "python3" is almost 17% longer. We're a lazy bunch! :-)
>
> And my touch typing accuracy/speed drops pretty noticably when I have
> to use the top row of keys...

This is why shells have the ability to create aliases, and also why
command-line autocomplete was invented :-)





==============================================================================
TOPIC: numpy.where() and multiple comparisons
http://groups.google.com/group/comp.lang.python/t/252e25bda74254c2?hl=en
==============================================================================

== 1 of 4 ==
Date: Fri, Jan 17 2014 5:51 pm
From: John Ladasky


Hi folks,

I am awaiting my approval to join the numpy-discussion mailing list, at scipy.org. I realize that would be the best place to ask my question. However, numpy is so widely used, I figure that someone here would be able to help.

I like to use numpy.where() to select parts of arrays. I have encountered what I would consider to be a bug when you try to use where() in conjunction with the multiple comparison syntax of Python. Here's a minimal example:

Python 3.3.2+ (default, Oct 9 2013, 14:50:09)
[GCC 4.8.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> a = np.arange(10)
>>> a
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> b = np.where(a < 5)
>>> b
(array([0, 1, 2, 3, 4]),)
>>> c = np.where(2 < a < 7)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Defining b works as I want and expect. The array contains the indices (not the values) of a where a < 5.

For my definition of c, I expect (array([3, 4, 5, 6]),). As you can see, I get a ValueError instead. I have seen the error message about "the truth value of an array with more than one element" before, and generally I understand how I (accidentally) provoke it. This time, I don't see it. In defining c, I expect to be stepping through a, one element at a time, just as I did when defining b.

Does anyone understand why this happens? Is there a smart work-around? Thanks.




== 2 of 4 ==
Date: Fri, Jan 17 2014 6:16 pm
From: duncan smith


On 18/01/14 01:51, John Ladasky wrote:
> Hi folks,
>
> I am awaiting my approval to join the numpy-discussion mailing list, at scipy.org. I realize that would be the best place to ask my question. However, numpy is so widely used, I figure that someone here would be able to help.
>
> I like to use numpy.where() to select parts of arrays. I have encountered what I would consider to be a bug when you try to use where() in conjunction with the multiple comparison syntax of Python. Here's a minimal example:
>
> Python 3.3.2+ (default, Oct 9 2013, 14:50:09)
> [GCC 4.8.1] on linux
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import numpy as np
>>>> a = np.arange(10)
>>>> a
> array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>>> b = np.where(a < 5)
>>>> b
> (array([0, 1, 2, 3, 4]),)
>>>> c = np.where(2 < a < 7)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
>
> Defining b works as I want and expect. The array contains the indices (not the values) of a where a < 5.
>
> For my definition of c, I expect (array([3, 4, 5, 6]),). As you can see, I get a ValueError instead. I have seen the error message about "the truth value of an array with more than one element" before, and generally I understand how I (accidentally) provoke it. This time, I don't see it. In defining c, I expect to be stepping through a, one element at a time, just as I did when defining b.
>
> Does anyone understand why this happens? Is there a smart work-around? Thanks.
>


>>> a = np.arange(10)
>>> c = np.where((2 < a) & (a < 7))
>>> c
(array([3, 4, 5, 6]),)
>>>

Duncan




== 3 of 4 ==
Date: Fri, Jan 17 2014 8:00 pm
From: John Ladasky


On Friday, January 17, 2014 6:16:28 PM UTC-8, duncan smith wrote:

> >>> a = np.arange(10)
> >>> c = np.where((2 < a) & (a < 7))
> >>> c
> (array([3, 4, 5, 6]),)

Nice! Thanks!

Now, why does the multiple comparison fail, if you happen to know?





== 4 of 4 ==
Date: Sat, Jan 18 2014 12:50 am
From: Peter Otten <__peter__@web.de>


John Ladasky wrote:

> On Friday, January 17, 2014 6:16:28 PM UTC-8, duncan smith wrote:
>
>> >>> a = np.arange(10)
>> >>> c = np.where((2 < a) & (a < 7))
>> >>> c
>> (array([3, 4, 5, 6]),)
>
> Nice! Thanks!
>
> Now, why does the multiple comparison fail, if you happen to know?

2 < a < 7

is equivalent to

2 < a and a < 7

Unlike `&` `and` cannot be overridden (*), so the above implies that the
boolean value bool(2 < a) is evaluated. That triggers the error because the
numpy authors refused to guess -- and rightly so, as both implementable
options would be wrong in a common case like yours.

(*) I assume overriding would collide with short-cutting of boolean
expressions.






==============================================================================
TOPIC: Python Scalability TCP Server + Background Game
http://groups.google.com/group/comp.lang.python/t/8234bf03949a8164?hl=en
==============================================================================

== 1 of 6 ==
Date: Fri, Jan 17 2014 11:44 pm
From: phiwer@gmail.com


> Quick smoke test. How big are your requests/responses? You mention
>
> REST, which implies they're going to be based on HTTP. I would expect
>
> you would have some idea of the rough size. Multiply that by 50,000,
>
> and see whether your connection can handle it. For instance, if you
>
> have a 100Mbit/s uplink, supporting 50K requests/sec means your
>
> requests and responses have to fit within about 256 bytes each,
>
> including all overhead. You'll need a gigabit uplink to be able to
>
> handle a 2KB request or response, and that's assuming perfect
>
> throughput. And is 2KB enough for you?
>
>
>
> ChrisA

My assumption is that there will be mostly reads and some writes; maybe in the order of 80-20%. There is a time element in the game, which forces player's entity to update on-demand. This is part of the reason why I wanted the server to be able to handle so many reques, so that it could handle the read part without having any caching layer.

Let me explain a bit more about the architecture, and possible remedies, to give you an idea:

* On top are the web servers exposing a REST api.

* At the bottom is the game.

* Communication betweeen these layers is handled by a simple text protocol using TCP.

The game has a tick function every now and then, which forwards the game's time. If a player enters the game, a message is sent to the game server (querying for player details), and if the game's tick is greater than the cached version of the player details, then the game updates the player details (and caches it).

This design obviously has its flaws. One being that both reads/writes has to pass through the game server. One way to remedy this is by using a new layer, on top of the game, which would hold the cache. But then another problem arises, that of invalidating the cache when a new tick has been made. I'm leaning towards letting the cache layer check the current tick every now and then, and if new tick is available, update a local variable in the cache (which each new connection would check against). Any thoughts regarding this?

There are some periods in the game, where many people will be online during the same tick, which could potentially cause the game to become slow at times, but maybe this should be accepted for the pleasure of making the game in python... :D

A follow-up question (which is more to the point really): How does other python game development frameworks solve this issue? Do they not use greenlets for the network layer, to be able to use the shared Queue from multiprocess? Do they only use one process for both network and game operations?

On a side note, I'm considering using 0MQ for the message layering between services (web-server <-> cache <-> game) on the back-end. Besides being a great message protocol, it also has built in queues which might be able to remedy the situation when many clients are requesting data. Anyone with experience with regards to this?

(This problem can be boggled down multiple producer, single consumer, and then back to producer again).

Thanks for all the replies.

/Phil




== 2 of 6 ==
Date: Sat, Jan 18 2014 12:01 am
From: Chris Angelico


On Sat, Jan 18, 2014 at 6:44 PM, <phiwer@gmail.com> wrote:
>> Quick smoke test. How big are your requests/responses? You mention
>>
>> REST, which implies they're going to be based on HTTP. I would expect
>>
>> you would have some idea of the rough size. Multiply that by 50,000,
>>
>> and see whether your connection can handle it. For instance, if you
>>
>> have a 100Mbit/s uplink, supporting 50K requests/sec means your
>>
>> requests and responses have to fit within about 256 bytes each,
>>
>> including all overhead. You'll need a gigabit uplink to be able to
>>
>> handle a 2KB request or response, and that's assuming perfect
>>
>> throughput. And is 2KB enough for you?
>>
>>
>>
>> ChrisA
>
> My assumption is that there will be mostly reads and some writes; maybe in the order of 80-20%. There is a time element in the game, which forces player's entity to update on-demand. This is part of the reason why I wanted the server to be able to handle so many reques, so that it could handle the read part without having any caching layer.
>

(You're using Google Groups, which means your replies are
double-spaced and your new text is extremely long lines. Please fix
this, either by the fairly manual job of fixing every post you make,
or the simple method of switching to a better client. Thanks.)

My point was just about the REST API, nothing else. You have to handle
a request and a response for every API call. Whether they're reads or
writes, you need to receive an HTTP request and send an HTTP response
for each one. In order to support the 50k requests per second you hope
for, you would have to handle 50k requests coming in and 50k responses
going out. To do that, you would need - at a very VERY rough estimate
- a maximum request size of 2KB and a gigabit internet connection
(which is expensive). No further calculations are worth pursuing if
you can't handle those requests and responses.

(And small requests tend to be more expensive than large ones. Since
you'll need a minimum of >SYN, <SYN/ACK, >ACK, >DATA, <DATA, >FIN,
<FIN/ACK, >ACK in order to transmit and receive one single packet's
worth of data each way, you're looking at roughly 8 packets minimum
for a one-byte message and one-byte response. But at a very very rough
estimate, 2KB each direction is the most you can sustain.)

ChrisA




== 3 of 6 ==
Date: Sat, Jan 18 2014 3:54 am
From: phiwer@gmail.com


> (You're using Google Groups, which means your replies are
>
> double-spaced and your new text is extremely long lines. Please fix
>
> this, either by the fairly manual job of fixing every post you make,
>
> or the simple method of switching to a better client. Thanks.)
>
>
>
> My point was just about the REST API, nothing else. You have to handle
>
> a request and a response for every API call. Whether they're reads or
>
> writes, you need to receive an HTTP request and send an HTTP response
>
> for each one. In order to support the 50k requests per second you hope
>
> for, you would have to handle 50k requests coming in and 50k responses
>
> going out. To do that, you would need - at a very VERY rough estimate
>
> - a maximum request size of 2KB and a gigabit internet connection
>
> (which is expensive). No further calculations are worth pursuing if
>
> you can't handle those requests and responses.
>
>
>
> (And small requests tend to be more expensive than large ones. Since
>
> you'll need a minimum of >SYN, <SYN/ACK, >ACK, >DATA, <DATA, >FIN,
>
> <FIN/ACK, >ACK in order to transmit and receive one single packet's
>
> worth of data each way, you're looking at roughly 8 packets minimum
>
> for a one-byte message and one-byte response. But at a very very rough
>
> estimate, 2KB each direction is the most you can sustain.)
>
>
>
> ChrisA


Aha, thanks for the info.

But the assumptions you are making does not answer the question.

And the question you raise, although important, is more a financial one,
not really relevant to the questions I posed.

Regards,
Phil




== 4 of 6 ==
Date: Sat, Jan 18 2014 4:13 am
From: Asaf Las


On Wednesday, January 15, 2014 8:37:25 PM UTC+2, phi...@gmail.com wrote:
> My problem is as follows:
> ....
> 2) The network layer of the game server runs a separate process as well,
> and my intention was to use gevent or tornado (http://nichol.as/asynchronous-
>servers-in-python).
> 3) The game server has a player limit of 50000. My requirement/desire is to
> be able to serve 50k requests per second
> 4) The game is not a real-time based game, but is catered towards the web.
> Due to this information, I have developed the initial server using netty in
> java. I would, however, rather develop the server using python,... and then
> use python for the frontend. ...

do you have references to implementations where python was used as frontend for such traffic load?

you can have a look to this group for numbers
https://groups.google.com/forum/#!forum/framework-benchmarks

Asaf




== 5 of 6 ==
Date: Sat, Jan 18 2014 4:40 am
From: phiwer@gmail.com


Den lördagen den 18:e januari 2014 kl. 13:13:47 UTC+1 skrev Asaf Las:
> On Wednesday, January 15, 2014 8:37:25 PM UTC+2, phi...@gmail.com wrote:
>
> > My problem is as follows:
>
> > ....
>
> > 2) The network layer of the game server runs a separate process as well,
>
> > and my intention was to use gevent or tornado (http://nichol.as/asynchronous-
>
> >servers-in-python).
>
> > 3) The game server has a player limit of 50000. My requirement/desire is to
>
> > be able to serve 50k requests per second
>
> > 4) The game is not a real-time based game, but is catered towards the web.
>
> > Due to this information, I have developed the initial server using netty in
>
> > java. I would, however, rather develop the server using python,... and then
>
> > use python for the frontend. ...
>
>
>
> do you have references to implementations where python was used as frontend for such traffic load?
>
>
>
> you can have a look to this group for numbers
>
> https://groups.google.com/forum/#!forum/framework-benchmarks
>
>
>
> Asaf

Yes I've looked at those charts, and that was one of the reasons why I decided
to go with netty for the back-end (although I'm probing to see if python
possibly could match in some way, which I haven't thought of yet...).

With regards to front-end, I haven't fully decided upon which framework to use.
It's easier to scale the front-end, however, given that the problem of
locking game state is not present in this logical part of the architecture.




== 6 of 6 ==
Date: Sat, Jan 18 2014 5:19 am
From: Mark Lawrence



On 18/01/2014 12:40, phiwer@gmail.com wrote:

[snip the stuff I can't help with]

Here's the link you need to sort the problem with double spacing from
google groups https://wiki.python.org/moin/GoogleGroupsPython

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence






==============================================================================
TOPIC: doctests compatibility for python 2 & python 3
http://groups.google.com/group/comp.lang.python/t/e83b94c8f7e04717?hl=en
==============================================================================

== 1 of 1 ==
Date: Sat, Jan 18 2014 12:39 am
From: Albert-Jan Roskam


--------------------------------------------
On Fri, 1/17/14, Terry Reedy <tjreedy@udel.edu> wrote:

Subject: Re: doctests compatibility for python 2 & python 3
To: python-list@python.org
Date: Friday, January 17, 2014, 10:10 PM

On 1/17/2014 7:14 AM, Robin Becker
wrote:

> I tried this approach with a few more complicated
outcomes and they fail
> in python2 or 3 depending on how I try to render the
result in the doctest.

I never got how you are using doctests. There were certainly
not meant for heavy-duty unit testing, but for testing
combined with explanation. Section 26.2.3.7. (in 3.3)
Warnings warns that they are fragile to even single char
changes and suggests == as a workaround, as 'True' and
'False' will not change. So I would not reject that option.


=====> I used doctests in .txt files and I converted ALL of them when I wanted to make my code work for both Python 2 and 3. I tried to fix something like a dozen of them so they'd work in Python 2.7 and 3,3. but I found it just too cumbersome and time consuming. The idea of doctest is super elegant, but it is really only meant for testable documentation (maybe with sphinx). If you'd put all the (often boring, e.g. edge cases) test cases in docstrings, the .py file will look very cluttered. One thing that I missed in unittest was Ellipsis, but: https://pypi.python.org/pypi/gocept.testing/1.6.0 offers assertEllipsis and other useful stuff.

Albert-Jan







==============================================================================
TOPIC: Guessing the encoding from a BOM
http://groups.google.com/group/comp.lang.python/t/1b4501ed3e9e2af1?hl=en
==============================================================================

== 1 of 2 ==
Date: Sat, Jan 18 2014 1:41 am
From: Gregory Ewing


Chris Angelico wrote:
> On Fri, Jan 17, 2014 at 8:10 PM, Mark Lawrence <breamoreboy@yahoo.co.uk> wrote:
>
>Every time I see it I picture Inspector
>>Clouseau, "A BOM!!!" :)
>
> Special delivery, a berm! Were you expecting one?

A berm? Is that anything like a shrubbery?

--
Greg




== 2 of 2 ==
Date: Sat, Jan 18 2014 2:10 am
From: Chris Angelico


On Sat, Jan 18, 2014 at 8:41 PM, Gregory Ewing
<greg.ewing@canterbury.ac.nz> wrote:
> Chris Angelico wrote:
>>
>> On Fri, Jan 17, 2014 at 8:10 PM, Mark Lawrence <breamoreboy@yahoo.co.uk>
>> wrote:
>>
>> Every time I see it I picture Inspector
>>>
>>> Clouseau, "A BOM!!!" :)
>>
>>
>> Special delivery, a berm! Were you expecting one?
>
>
> A berm? Is that anything like a shrubbery?

http://www.youtube.com/watch?v=GLDvtpSC_98

ChrisA





==============================================================================
TOPIC: python to enable javascript , tried selinium, ghost, pyQt4 already
http://groups.google.com/group/comp.lang.python/t/a453f34131ad9343?hl=en
==============================================================================

== 1 of 1 ==
Date: Sat, Jan 18 2014 3:54 am
From: Jaiprakash Singh


hi,

can you please suggest me some method for study so that i can scrap a site having JavaScript behind it


i have tried selenium, ghost, pyQt4, but it is slow and as a am working with thread it sinks my ram memory very fast.




==============================================================================

You received this message because you are subscribed to the Google Groups "comp.lang.python"
group.

To post to this group, visit http://groups.google.com/group/comp.lang.python?hl=en

To unsubscribe from this group, send email to comp.lang.python+unsubscribe@googlegroups.com

To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.python/subscribe?hl=en

To report abuse, send email explaining the problem to abuse@googlegroups.com

==============================================================================
Google Groups: http://groups.google.com/?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate