hate these ads?, log in or register to hide them
Page 1 of 3 123 LastLast
Results 1 to 20 of 42

Thread: [DEVBLOG] carbonio and bluenet: next level network technolog

  1. #1
    Joe Appleby's Avatar
    Join Date
    April 9, 2011
    Location
    in front of the class
    Posts
    3,092

    [DEVBLOG] carbonio and bluenet: next level network technolog

    Quote Originally Posted by [url=http://www.eveonline.com/devblog.asp?a=blog&bid=925
    carbonio and bluenet: next level network technology[/url]]
    Most folks familiar with EVE know that it's built on Python, Stackless Python to be specific. Stackless is a micro-threading framework built on top of Python allowing for millions of threads to be live, without a lot of additional cost from just being Python. It is still Python and that means dealing with the Global Interpreter Lock (hereafter known as the damn stinkin' GIL, or just GIL for short).

    The GIL is a serial lock that makes sure only a single thread of execution can access the Python interpreter (and all of its data) at a time. So as much as Stackless Python feels like a multi-threaded implementation, with the trappings of task separation, channels, schedulers, shared memory and such, it can only run a single task at any given time. This is not unlike some of the co-operative multitasking operating systems of the past, there is power in this model as the framework makes the promise to all executing threads that they will not be preemptively ended by the system (apart from when the system is suspecting the micro thread to be in violation of the Halting problem). This allows game logic code to make a lot of assumptions on global program state, saving a lot of complexities which would be involved in writing the acres of game logic that make up EVE Online to be written in a callback driven asynchronous manner. In fact most of the high level logic in CCP products looks naively procedurally synchronous, which helps a lot with the speed of development and maintainability for the code.

    The down side of all of this is that some of the framework code in EVE Online is written in Python and is thus victim to the GIL. This includes any C-level module that wants to access Python data, the GIL must be acquired before it so much as looks at a string

    [center:3dmwy9ul]
    All tasks working within Python must acquire the singular GIL to legally process, effectively limiting all Python to a single thread of execution.
    (please excuse the primitive graph, I'm a programmer not an artist)
    [/center:3dmwy9ul]
    Bottom line: Code written in Stackless Python can only execute as fast as your fastest CPU core can go. A 4 or 8 CPU big-iron server will burn up a single CPU and leave the others idle, unless we span more nodes to harness the other CPUs, which works well for a lot of the logic in EVE which is stateless or only mildly reliant on shared state but presents challenges in logic which is heavily reliant on shared state, such as space simulation and walking around space stations.

    This is not a problem as long as a single CPU can handle your load, and for sane uses of Python this is true. I shouldn't have to tell you that we are hitting the point at which a single CPU can't process a large fleet fight, despite the work of teams like Gridlock in squeezing out every drop of optimization that they can. CPUs are not getting any faster. They are getting more cache, fatter busses and better pipelines, but not really any faster at doing what EVE needs done. The way of the near (and perhaps far) future is to 'go wide' and run on multiple CPUs simultaneously.

    Overall the proliferation of multi-core CPUs is good in the long term for EVE, the basic clustering method that EVE uses will work really well for computers with more than 30-60 cores, as then the routing between cores eclipses the benefit of having the threads of a process flow between the cores but right now we are in the spot where the framework parts of EVE, such as networking and general IO could benefit a lot from being liberated from the GIL.

    Multi-core superscalar hardware is good news for modern MMOs, they are well-suited to this paradigm and trivially parallelizable, but not-so-good news for Python-dependent EVE. It's not news: now more than ever, performance critical EVE systems which do not need the benefits of rapid development and iteration in Python need to decouple themselves from the GIL, and soon. CarbonIO is a giant leap in that direction.

    CarbonIO is the natural evolution of StacklessIO. Under the hood, it is a completely new engine, written from scratch with one overriding goal tattooed on its forehead: marshal network traffic off the GIL and allow any c++ code to do the same. That second part is the big deal, and it took the better part of a year to make it happen.

    Backing up for just one minute, StacklessIO (http://www.eveonline.com/devblog.asp?a=blog&bid=584) was a quantum leap forward for Stackless Python networking. By making network operations "Stackless aware" a blocking operation is offloaded to a non-GIL-locked thread which can complete its wait while Stackless continues processing, and then re-acquires the GIL, notifying Stackless that the operation has completed. This lets the receive run in parallel, allowing communications to flow at OS-level speeds and be fed as-needed into Python as fast as they can be consumed.

    [center:3dmwy9ul]
    stacklessIO completes Python requests without holding the GIL[/center:3dmwy9ul]

    CarbonIO takes that a step further. By running a multi-threaded communications engine entirely outside the GIL, the interactivity between Python and the system is decoupled completely. It can send and receive without Python asking it to.

    That bears repeating: CarbonIO can send and receive data without Python asking it to. Concurrently. Without the GIL.

    When a connection is established through CarbonIO a WSARecv() call is immediately issued and data begins to accumulate. That data is decrypted, uncompressed, and parsed into packets by a pool of threads that operate concurrently to any Python processing. These packets are then queued up and wait for Python to ask for them.

    When Python decides it wants a packet, it calls down to CarbonIO, which probably already has the data ready. That means data is popped off the queue and returned without ever yielding the GIL. It's effectively instant, or at least nano-secondly fast. That's the first big gain of CarbonIO, its ability to do parallel read-ahead.

    The second big gain is on sends. Data is queued to a worker thread in its raw form, and then Python is sent on its way. The compression, encryption, packetization and actual WSASend() call all occur off the GIL in another thread, which allows the OS to schedule it concurrently on another CPU. A method is provided to allow c++ code to do the same, but that requires no special architectural overhaul, StacklessIO could have done that too, but without the whole picture it would have been pointless.

    Now back up a minute. "Already has the data ready". Hmm. What if we were to install a c++ callback hook that allowed a non-Python module to get that data without ever touching Machonet? Welcome to BlueNet.

    [center:3dmwy9ul]
    CarbonIO runs its recv-loop continuously, and can notify a c++ module of data arriving without Python intervention.
    [/center:3dmwy9ul]

    Machonet is a large collection of functionality which marshals, routes, manages sessions, handles packet scheduling/delivery and all the other glue that holds EVE together. It is a Python module, so all data must pass through the cursed GIL at some point, on every EVE node. No matter how fast a c++ module is for EVE, it is still beholden to that bottleneck. This discourages a lot of potential c++ optimizations, since any gain would be chewed up acquiring the GIL and thunking into Machonet.

    But not anymore.

    Now a c++ system can receive and send packets through BlueNet and never care about or need to acquire the GIL. This was originally coded for Incarna, which needs to send a significantly higher volume of movement packets to support a walk-around MMO. In space you can cheat, but not so with close-up anthropomorphic motion. Early projections showed that even with a modest tick-rate, Incarna would bring the Tranquility cluster to its knees. BlueNet solves that problem by routing traffic in parallel with the GIL, to and from c++-native systems (like Physics). This is faster because the data stays in its native, bare-metal form and not double-thunked for every operation, a huge savings.

    How does this work? BlueNet maintains a read-only copy of all necessary Machonet structures, in addition to this a very small (8-10 byte) out-of-band header is prepended to all packets. This header contains routing information. When a packet arrives, BlueNet can inspect this out-of-band data and sensibly route it, either by forwarding it to another node or delivering it to a registered c++ application locally. If it forwards it, this happens in-place off the GIL; Machonet/Python is never invoked. This means our Proxies can route BlueNet packets entirely in parallel, and without the overhead of thunking to Python or de-pickling/re-pickling the data. How effective is this? We're not sure yet, but its somewhere between "unbelievably stunning" and "impossibly amazing" reductions in lag and machine load for systems where this is applicable. Seriously we can't publish findings yet, we don't believe them.

    In addition CarbonIO has a large number of ground-up optimizations, mostly small gains that add up to faster overall code, a few worth mentioning:

    Work Grouping

    It is difficult to be specific, but CarbonIO goes out of its way to "group" work together for processing. In a nutshell, certain operations have a fixed transactional overhead associated with them. Network engines have this in spades, but it applies to all significant programming, really. Through some pretty careful trickery and special kind of cheating it's possible to group a lot of this work together so many operations can be performed while paying the overhead only once. Like grouping logical packets together to be sent out in a single TCP/IP MTU (which EVE has always done). CarbonIO takes this idea several orders deeper. An easy example would be GIL acquisition aggregation.

    The first thread to try and acquire the GIL establishes a queue, so that any other threads trying to acquire it simply add their wake-up call to the end of the queue and go back to the pool. When the GIL finally does yield, the first thread drains the entire queue, without releasing/re-acquiring the GIL for each and every IO wakeup. On a busy server this happens a lot, and has been a pretty big win.

    openSSL integration

    CarbonIO implements SSL with openSSL and can engage this protocol without locking the GIL. The library is used only as a BIO pair, all the data routing is handled by CarbonIO using completion ports. This will allow us to take continued steps by making EVE more and more secure and even allows for some of the account management features of the web site to be moved over to the EVE client for convenience

    Compression integration

    CarbonIO can compress/decompress with zlib or snappy on a per-packet basis, again, independent of the GIL

    Field Trials

    Data collected over a 24-hour run of a busy proxy server (~1600 peak users, a typical week day) Showed the overall CPU% usage drop dramatically, as well as the per-user CPU%. This reflects gains from the overall paradigm of CarbonIO, which is to reduce transactional overhead. As the server becomes busy, the effectiveness of these optimizations begins to be dominated by the sheer number of transactions that must be performed, but at peak load it still showed a substantial gain.

    [center:3dmwy9ul]


    CPU% per user over a 24-hour run


    Raw CPU% used over the same 24-hour period[/center:3dmwy9ul]


    Sol nodes benefit much less from these modifications since their main job is game mechanics rather than network activity, but we still saw measurable improvement in the 8%-10% range.

    It is important to note that none of the BlueNet options were engaged with these trials, no c-routing, no off-GIL compression/encryption. These were meant to be in-place process-alike tests which were fearlessly attempted on live loads to ‘proof' the code once we had thrashed it as much as we could in closed testing. The gains we see here are gravy compared to the performance gains we will see on modules that will use the new functionality.

    Bottom Line

    What this all means is that the EVE server is now better positioned to take advantage of modern server hardware, keeping it busier and doing more work, which in turn pushes the upper limit on single-system activity. By moving as much code away from the GIL as possible, it leaves more room for the code that must use it. In addition, since less code is competing for the GIL, the overall system efficiency goes up. With the addition of BlueNet and some very optimal code paths, the door is now open. How far it swings and what gains we end up getting remains to be seen, but at the very least we can say a major bottleneck has been removed.
    EDIT: done
    nevar forget

  2. #2
    Donor Snake's Avatar
    Join Date
    April 10, 2011
    Posts
    1,079

    Re: [DEVBLOG] carbonio and bluenet: next level network techn

    um, ok?

  3. #3

    Join Date
    April 10, 2011
    Posts
    24

    Re: [DEVBLOG] carbonio and bluenet: next level network techn

    woah...cool man...

  4. #4
    Tarminic's Avatar
    Join Date
    April 9, 2011
    Location
    Nashville, TN
    Posts
    2,908

    Re: [DEVBLOG] carbonio and bluenet: next level network techn

    I haven't done serious application development in some time, but that is pretty damned clever.

    Status of Babby: 100% Formed

  5. #5
    Herschel Yamamoto's Avatar
    Join Date
    April 13, 2011
    Location
    Illuminati derpy herp
    Posts
    3,129

    Re: [DEVBLOG] carbonio and bluenet: next level network techn

    I'm not enough of a coding geek to be sure of my parsing here, so I'll ask. tl;dr, they figured out how to make Python multithreaded for some important applications, and delete a lot of overhead doing it, which makes some applications literally run twice as fast?
    "Make no mistake, Communism lost a big argument - one we know today as the 20th century."

    Quote Originally Posted by Wall View Post
    Herschel Yamamoto is owning in this thread.

  6. #6
    Malcanis's Avatar
    Join Date
    April 12, 2011
    Posts
    4,002

    Re: [DEVBLOG] carbonio and bluenet: next level network techn

    Oblig. "why are they wasting time on this when they should be fixing lag?"

  7. #7
    Seleene's Avatar
    Join Date
    April 10, 2011
    Posts
    310

    Re: [DEVBLOG] carbonio and bluenet: next level network techn

    I am very angry because CCP seems biased against pie graphs.

  8. #8
    Donor Mike deVoid's Avatar
    Join Date
    April 9, 2011
    Location
    Liverpool, UK :: lowsec
    Posts
    5,013

    Re: [DEVBLOG] carbonio and bluenet: next level network techn

    I didn't really understand the technicalities (not a coder) but I left pretty impressed.

    They'll be able to take advantage of multiple cores for each node soon?
    Countries do not exist where I am from. The discovery of the Higgs boson led to limitless power, the elimination of poverty and Kit-Kats for everyone. It is a communist chocolate hellhole and I'm here to stop it ever happening.
    Make isk with PI
    The Great Tracking Nerf v0.1
    My fav ECM alternative

  9. #9
    Marlona Sky's Avatar
    Join Date
    April 10, 2011
    Posts
    3,969

    Re: [DEVBLOG] carbonio and bluenet: next level network techn

    Anyone got layman's terms for us non-computer geeks?

  10. #10

    Join Date
    April 13, 2011
    Posts
    2,615

    Re: [DEVBLOG] carbonio and bluenet: next level network techn

    Quote Originally Posted by Marlona Sky
    Anyone got layman's terms for us non-computer geeks?
    They can't multithread python, they can't make it work on more than one core. That doesn't bother them that much because they can effectively run many "pythons"; one per system, for example, and dole them out one per CPU. They can decrease the load on each cpu further by asking each python thread to do less; anything that isn't python can be handed off to other cores and run in parallel. In this case, they've handed over all networking operations, all data retrieval and suchlike, to code that isn't python. This means that, once this rolls out, they'll be closer to a state where only the code that absolutely positively must use python uses python, rather than everything fighting over each cpu, as they've got now. As well as reducing cpu load, that opens up a load of fancy out-of-order retrieval and caching tricks that simply weren't available in a pure python world.

    tl;dr, shit just got a whole lot more efficient.

  11. #11
    Tarminic's Avatar
    Join Date
    April 9, 2011
    Location
    Nashville, TN
    Posts
    2,908

    Re: [DEVBLOG] carbonio and bluenet: next level network techn

    So if I'm reading this correctly, the python microthreads become less and less about performing calculations and more about retrieving the results of those calculates from somewhere outside the threaded environment asynchronously?

    Status of Babby: 100% Formed

  12. #12
    RoemySchneider's Avatar
    Join Date
    April 9, 2011
    Posts
    3,092

    Re: [DEVBLOG] carbonio and bluenet: next level network techn

    [...]Incarna, which needs to send a significantly higher volume of movement packets to support a walk-around MMO.
    [...]
    Early projections showed that even with a modest tick-rate, Incarna would bring the Tranquility cluster to its knees.
    "we freed up some hamster power but incarna ate it so the avatars could walk more smoothly"

  13. #13
    Cydo's Avatar
    Join Date
    April 9, 2011
    Posts
    740

    Re: [DEVBLOG] carbonio and bluenet: next level network techn

    Seems cool, but 12hours till' incarna and they still haven't released the patch notes.

    Instead we get this

  14. #14
    Ampoliros's Avatar
    Join Date
    April 10, 2011
    Location
    Aperture Harmonics
    Posts
    1,003

    Re: [DEVBLOG] carbonio and bluenet: next level network techn

    Quote Originally Posted by RoemySchneider
    [...]Incarna, which needs to send a significantly higher volume of movement packets to support a walk-around MMO.
    [...]
    Early projections showed that even with a modest tick-rate, Incarna would bring the Tranquility cluster to its knees.
    "we freed up some hamster power but incarna ate it so the avatars could walk more smoothly"
    alternatively, "incarna helped reduce load on the servers"

    but don't mind me, continue your bitterness, you were going well

  15. #15
    Doomed Predator's Avatar
    Join Date
    June 17, 2011
    Posts
    1,079

    Re: [DEVBLOG] carbonio and bluenet: next level network techn

    Gave up near the middle, gonna assume this is a good thing.

  16. #16

    Join Date
    April 11, 2011
    Posts
    1,389

    Re: [DEVBLOG] carbonio and bluenet: next level network techn

    LOL python.

    I'm sure in the end, python is just going to be torn out of performance critical parts of the code altogether.

  17. #17

    Join Date
    April 18, 2011
    Posts
    181

    Re: [DEVBLOG] carbonio and bluenet: next level network techn

    For the TL;DR crowd, what I think is key here:

    How effective is this? We're not sure yet, but its somewhere between "unbelievably stunning" and "impossibly amazing" reductions in lag and machine load for systems where this is applicable. Seriously we can't publish findings yet, we don't believe them.
    So basically, remember what StacklessIO did to our lag? It's kinda like that, but more.

  18. #18
    Rakshasa The Cat's Avatar
    Join Date
    April 18, 2011
    Location
    Jita 4-4
    Posts
    2,798

    Re: [DEVBLOG] carbonio and bluenet: next level network techn

    Techically elmicker, they can run python on more than one core/thread just not simultaneously due to the GIL. So even if they have multiple threads each can use python as long as the others are busy doing other stuff e.g. sending/receiving data from RPC calls, etc.
    Quote Originally Posted by Random hopeful w-space dweller
    I'm excited about the nebulas, at least it's something I will see out in the wormholes.

  19. #19
    Rake Mizar's Avatar
    Join Date
    April 10, 2011
    Posts
    143

    Re: [DEVBLOG] carbonio and bluenet: next level network techn

    These are the craziest patch notes I've ever seen.

  20. #20

    Join Date
    April 10, 2011
    Posts
    1,375

    Re: [DEVBLOG] carbonio and bluenet: next level network techn

    Team Gridlock and BFF, true heros of EVE

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •