We're sorry but this page doesn't work properly without JavaScript enabled. Please enable it to continue.
Feedback

What’s happening in your Rails app?

00:00

Formale Metadaten

Titel
What’s happening in your Rails app?
Untertitel
Introduction to Introspection features of Ruby
Serientitel
Teil
38
Anzahl der Teile
94
Autor
Lizenz
CC-Namensnennung - Weitergabe unter gleichen Bedingungen 3.0 Unported:
Sie dürfen das Werk bzw. den Inhalt zu jedem legalen und nicht-kommerziellen Zweck nutzen, verändern und in unveränderter oder veränderter Form vervielfältigen, verbreiten und öffentlich zugänglich machen, sofern Sie den Namen des Autors/Rechteinhabers in der von ihm festgelegten Weise nennen und das Werk bzw. diesen Inhalt auch in veränderter Form nur unter den Bedingungen dieser Lizenz weitergeben.
Identifikatoren
Herausgeber
Erscheinungsjahr
Sprache

Inhaltliche Metadaten

Fachgebiet
Genre
Abstract
We will talk about introspection features of Ruby interpreter (MRI) to solve troubles on your Ruby on Rails application. Rails application development with Ruby is basically fast and easy. However, when you have trouble such as tough bugs in your app, performance issues and memory consumption issues, they are difficult to solve without tooling. In this presentation, I will show you what kind of introspection features MRI has and how to use them with your Rails application.
MultiplikationsoperatorDialektGoogolVirtuelle MaschineMathematikMonster-GruppeMailing-ListeSoftwareentwicklerPatch <Software>ProgrammfehlerKartesische KoordinatenArithmetisches MittelZahlenbereichHackerHalbleiterspeicherFormale SpracheOrtsoperatorComputerspielSoftwareentwicklungPunktModelltheorieGeradeCoxeter-GruppeGewicht <Ausgleichsrechnung>InternetworkingGruppenoperationMereologieTypentheorieSoundverarbeitungOvalZellularer AutomatHilfesystemComputeranimation
ComputerFramework <Informatik>Kartesische KoordinatenWort <Informatik>SchlüsselverwaltungSpeicherabzugParametersystemMathematikPhysikalisches SystemSchreiben <Datenverarbeitung>InformatikProgrammiergerätBlackboxRechenschieberInterpretiererMultiplikationsoperatorRuby on RailsCoxeter-Gruppet-TestNormalvektorMereologieVarianzLoopMomentenproblemResultanteDemoszene <Programmierung>RechenwerkVorzeichen <Mathematik>MAPSoftwareentwicklungVerkehrsinformationVideokonferenzPunktOffenes KommunikationssystemComputeranimation
Objekt <Kategorie>Elektronische PublikationSchreiben <Datenverarbeitung>Kartesische KoordinatenSpeicherbereinigungAuswahlaxiomProgrammierumgebungKonfigurationsraumProfil <Aerodynamik>SoftwareentwicklungProgrammbibliothekHalbleiterspeicherVariableSpeicherverwaltungNeuroinformatikProgrammfehlerLeckInformationAblaufverfolgungMereologieStatistikEinflussgrößeMiddlewareMultiplikationsoperatorCoprozessorGeradeDienst <Informatik>URLVirtuelle MaschineCodeQuellcodeRuby on RailsSupercomputerParametersystemGrundsätze ordnungsmäßiger DatenverarbeitungResultanteDigitalisierungMathematikProzess <Informatik>Physikalischer EffektMomentenproblemKardinalzahlHilfesystemSpeicherabzugGüte der AnpassungPolygonLesen <Datenverarbeitung>Ordnung <Mathematik>BeobachtungsstudieWärmeübergangOrtsoperatorSchlussregelSkriptspracheNP-hartes ProblemKonditionszahlGruppenoperationProdukt <Mathematik>FreewarePunktRechter WinkelComputeranimation
EreignishorizontZahlenbereichInformationObjekt <Kategorie>RechenschieberVerschlingungKartesische KoordinatenInterpretiererResultanteSpeicherbereinigungGeradeMultiplikationsoperatorSpeicherverwaltungBitStichprobenumfangStatistikArithmetisches MittelSchnittmengeSystemaufrufBenutzeroberflächeMotion CapturingPhysikalischer EffektElektronisches BuchAdditionRechter WinkelComputeranimation
SpeicherverwaltungGeradeHalbleiterspeicherObjekt <Kategorie>Web logInformationParametersystemURLKartesische KoordinatenVerschlingungZählenTUNIS <Programm>StatistikSpeicherbereinigungÜberlagerung <Mathematik>FlächeninhaltResultanteAblaufverfolgungComputeranimation
QuellcodeGlobale OptimierungGeradeElektronische PublikationCodeVerzeichnisdienstTheoretische PhysikRechter WinkelComputeranimation
Objekt <Kategorie>VariableLesezeichen <Internet>ZählenProfil <Aerodynamik>Spiegelung <Mathematik>Message-PassingFehlermeldungPunktStellenringDebuggingHook <Programmierung>ParametersystemAblaufverfolgungEreignishorizontHalbleiterspeicherGarbentheorieMittelwertProgrammfehlerGeradeEinfügungsdämpfungKartesische KoordinatenLokales MinimumProgrammiergerätFramework <Informatik>Automatische IndexierungTypentheorieZahlenbereichDichte <Physik>Rechter WinkelEnergiedichteDatenstrukturSensitivitätsanalyseSchnittmengeFlächeninhaltSichtenkonzeptZweiMetropolitan area networkSoftwareentwicklungComputeranimation
GeradeProgrammfehlerSoftwareAusnahmebehandlungGeometrische FrustrationSpeicherabzugSoftwareentwicklungPhysikalisches SystemFehlermeldungStellenringMaßerweiterungMAPKartesische KoordinatenFramework <Informatik>Primitive <Informatik>VariableOpen SourceHackerAutomatische IndexierungMultifunktionEinfacher RingMessage-PassingParametersystemMultiplikationsoperatorResultanteInterpretiererQuellcodeProgrammiergerätProgrammbibliothekAtomarität <Informatik>GruppenoperationComputerspielMathematische LogikZählenKugelkappeTopologieWärmeausdehnungEinsMereologieTwitter <Softwareplattform>PRINCE2Computeranimation
Transkript: Englisch(automatisch erzeugt)
So, today, my name is Koichi Sasada. I want to talk about what happened in your Ruby application.
So, I want to introduce some introspection feature of Ruby itself. At first, I want to summarize my presentation. So, I have talked about two topics. One, so, Google it.
Why is Google it? So, there are many, many existing tools to inspect your latest application, and there are many, many good resources. So, please check it. And so, in this presentation, I will provide several keywords,
so please check it. And also, I want to tell you that you can make your own tools using recent MRI. So, that is my topic, I want to say.
So, this is my introduction. I'm a member of MRI Committer since 2007, and I'm a developer, original developer.
I want to ask you how many people are using Ruby 1.8? Oh, only a few. Maybe, if you are using MRI,
then you are a user of my software. Thank you for using my software. So, the virtual machine is introduced from Ruby 1.9 and recent Ruby 2.2 also using the virtual machine.
So, unfortunately, I'm not a Rails programmer. My wife is a Rails programmer, so my wife is my customer, but I'm not a Rails programmer, I'm sorry. So, I'm a newbie, and this is the first time to attend Rails conference, so I'm very excited to talk here.
Thank you. So, this is a very important slide. Herock employs me,
and Herock has a booth at layer 3, and Herock, this afternoon, Herock shows a sponsor session, so please check it. And Herock employs us as a math team. So, we have three Japanese full-time Ruby commit developers.
So, our mission is design Ruby language itself and improve quality of MRI. Maybe quality means several meaning. So, one is no bugs.
And performance and low resources, such as low memory consumption. Our team are working on improving the quality of MRI. Our math team has three members.
Maybe, you know, math, designer and director of Ruby itself, and Nobu. So, he's very quite, quite active committer, and me, my nickname is K01 Koichi,
and I'm an internal hacker. He, Matsu, Matsu, Yukihiro Matsu-Moto, is a, so, maybe you don't need to, so, I don't need to tell you who is he, but he is known as a title collector.
So, he has many, many titles. I cannot list everything of his positions. And Nobu. So, Nobu is very active committer. So, if he finds bugs,
then he fixes bugs and includes bugs. And fixes again and again. So, this is the commit number of Nobu.
So, as you can see, so many commits created by Nobu. So, we say he's a patch monster. And also, I am an internal hacker, and also, I'm an EDD developer. So, this is a commit number of day by day,
of my changes, and there is several peaks. This is RubyConf. This is the release of Ruby 2.0. This one, this one, this one. So, everything is based before some events.
So, EDD is event-driven development. So, it means that if you invite me to some conferences, then Ruby performance will be improved. So, please invite me.
About recent achievements. So, much team and Ruby core team members achieve the release of Ruby 2.0. I have no time to explain everything. So, I skip the new features. Of Ruby 2.0, but
all of these slides will be uploaded. So, please take it if you have interest about what is the new feature of Ruby 2.2 or internal improvements. I want to show one improvement.
Maybe, so you are a Rails programmer and you love to write key word parameters. So, key word parameters is easy and useful, but it is slow. So, compare with normal method dispatch. So, compare with such a normal method dispatch,
it was 30 times slower. So, on Ruby 2.2, we improved the performance. So, it is faster than about 15 times faster. So, it is still slower,
but I think it is enough for us. And also, the next target of math team and our Ruby core team is Ruby 2.3. So, we are now planning some features
and we will release Ruby 2.3 at the end of this year. But, if you have any question, any ideas, any suggestions, then please catch me after this presentation.
So, today's topic is
what's happening in your Rails application. Introduction to Introspection Features of Ruby. This title is Dajaric Club. Dajaric Club is some kind of pang. So, the Dajaric Club is
created by our superhero, Aaron Patterson. So, of course, you know that he is very funny person. And many Japanese Rubyists also join in to say something like, pang.
So, something like this. But I skipped this one. So, I want to introduce Introspection Features of Ruby. Maybe you are working on Ruby on Rails and your application is
on the deep layers. So, of course, there is a hardware, there is an operating system, Ruby interpreter, and Ruby on Rails framework or other gems, and on such layers,
your application is built. Most of people, for most of people, such a low layer, low layers are black box. Maybe you don't know how to modify
Linux operating system or interpreters. So, it is very special, specialty things. So, computer science students need to know best. Maybe most of people don't know about that. And also, after three days,
your application is also black box. So, we need to review so, if you have trouble from such a black box, you need to understand what is happening in your application and your
computing systems. So, the question is how to inspect your layers application. My answer is to using existing tools
and make your own suitable tools. So, first of all, I want to introduce some existing tools. However, we have so many great presentations
at this Ruby conference. So, first to yesterday's presentations and Aaron's keynote was also great. So, I can cancel this presentation, but
I want to talk another aspect of such a topic. at first, the performance issue, how to overcome such a performance issue. The easiest way, easiest way to
overcome such a performance issue is to use performance dyno on Heroku. With performance dyno, you can use isolated computing resource and has huge memory,
6GB memory and many CP processors. But it's expensive, but maybe it is the easiest way. Of course, so you can use another high performance computing resource if you have money.
But sometimes we need to consider the money and so we need to tune your application. So at first, we need to separate the program.
For example, if you have a slow request issue, then you need to understand what is wrong. So which part is slow? So DB access or external AP access or your Ruby application is slow because of the garbage correction one. So what
you wrote some some bad code, you need to understand what is wrong. And also memory consuming issue, you need to understand who consumes the memory. So what's, which part of
code consumes the memory and so on. So one good thing is a good service is New Relic of course. So New Relic shows which part of your request consumes the time.
Maybe you are, you know more, you know more. I'm a newbie of Ruby on Rails. I need, so, and with New Relic you can measure more detail of virtual machine.
So this is important thing that you can use New Relic very easily on Heroku as a, at home. I'm an employee of Heroku so I need to say that. And also for performance,
using performance profiler is good choice to understand what, which part is slow. So I don't say that there is a bug, but even if it has bug it is very useful feature, useful tools. And maybe
stack profile or another performance profiler is written by Aman Gupta from GitHub. So please check his presentations. It was very useful features. So I want to talk about the memory consumption, how
to analyze the memory consumption. at first I, so of course we need we know that Ruby has GC, garbage collector you don't need to you don't need to manage
your object creation or deletion. So all of unused unused object recycled automatically so you don't need to care. Ruby 2.2 has incremental and garbage collection. So the
problem is so we can we can list the possible problems. So one is incorrect garbage collector GC parameters. So Ruby, Ruby's GC can tune by environment environment variables but it is difficult to choose the correct one.
And also if the program grabs the many objects unexpectedly it will be object leaking or memory leaking. And also MRI can have a bug. And Ruby 3.1
introduced generation garbage collection and generation garbage collection is so shortly only correct younger objects. So if some object promoted to old object unexpectedly it will be
object leaking. So we don't recycle old objects long time. So we understand what is the situation on your application. I want to introduce my two gems. There are many
other tools written by other people such as mempro by some stuff from but I want to this time I want to introduce my own gems. So one is gc-tracer to measure
garbage collection statistics and allocation tracer to find out object creation locations. So gc-tracer is very easy to use. You only need to require library and write gc-tracer start logging
and file name. So all of the information related to the information writes to this file, specified file. And allocation tracer in your application you can use these
source codes. I think it is very easy to use it. Only three lines you need to write. However, this is a Rails conference, not a Ruby conference. So maybe this I wrote I wrote lack middleware to use
these tools. So you only need to write gem file and writing a config.ru and enable middlewares. So it is easy to use for these applications I think.
But allocation tracer is a bit slow. Allocation tracer needs to trace creation object and creating object so it will be slow so you don't need to you shouldn't use this feature, this allocation tracer gem on your production application.
I prepare this demonstration application. So this application working on Heroku and on production environment but I enabled
both GC tracer and allocation tracer so you can check this application. This one. This is my first base application
using CSS. So you can you can sign slides you can appreciate you can appreciate something
like a big sample. So it sounds
a bit slow because allocation tracer is enabled. So you can see the link to
you can see the link to the statistic information from these links and you can see the result of GC tracer. So there are many, many information in this screen. So I can't introduce
everything but for example line is captured line means captured information. Each line is captured at the GC events. So for example end of sleep means sorry, GC garbage
collection has several phases so starting the marking phase and starting the end of the marking phase and starting the sleeping phase and end of the sleeping phase. So ending the sleeping end of the sleeping means end of the garbage collection. So each such event we capture all
of the information and also tick is non-second time from epoch time. So it is very big number but you can manipulate these tick numbers to get how much how long garbage collection use.
And also it's, for example total allocated sorry, total allocated object so this line this column. So total allocated object and total freed object
is the so you can, easy to understand so how many objects are created and freed in this Ruby interpreter.
So getting the log then you can choose the correct GC parameters and you can get the reason why your application has many memories but it is difficult maybe this blog post written by Sam Safron will help you
please send your log to me so I can advise if you are a Heroku VIP customer so it is a joke so I welcome everyone
so I want to get many statistics to understand how to tune garbage collection so and also sometimes sometimes someone ask me why my application
consume so much memory without any information I'm not magician I'm not a wizard so I can't understand what happen on your application but with this log this is the I can understand
what happen in your application so please ask me with this log with allocation tracer we can see the allocation tracer log from this link
this one so this shows so which line which location consume the sorry object are created at where the location
so it means that this line this line creates 4000 object so this is sorted by the path name and you can sort with the count of created object or other parameters
for example so this okay so this log
is captured after 1000 request
okay after 1000 request so compare with other lines so these these lines create many many objects we can understand
so checking this checking this source code so 36 lines
it is difficult to read but this code search the directory entries and checking the all stamps files so these lines can be cached we can understand
after this optimization you can check you can check the problem was solved there are other parameters such as count and all the objects count and average age of
objects age means how many GC how many GC survived for each object and minimum ages and maximum ages and consumed memory
so using such tools you can specify what is wrong and what you should do so the last section
is how to review what the performance issues so if you got some error unexpected behavior so we have many tools so debugger or modify error message maybe you
always use better errors to see what is the error message and also I want to introduce other Digimin gem and pretty bugless gems Digimin gem is
written by Yuksong this gem is very clever for example if you typo there is no F1 name it will be a name error
however with Digimin first name message it suggests a similar name it is very nice features and also pretty bugless gem is written by myself and this shows error message
is local variables values so each line each bug you can see the variables and the value of the name so there are many
existing profiling tools or some clever tools if you have no suitable tools for your issue then you can make it so this will be MRI provides many features to make
such a tool for example trace point trace point trace point is insert hooks for some events and also you can modify your
favorite frame message and bug traces and also there are reflection features and debug inspect gem and more and more so please check it I want to show some examples so for example I'm a newbie of latest application programmer
so I want to if I want to know where the index method calls when I can when I write this trace point hook and place at the start beginning of the application we can see the
we can see the we can see the we can see the so long bug trace with only a few lines so I can understand where the index
method is called and other example maybe if you got error message you got maybe you got frustration but if you error message shows a heart mark then maybe we can calm down
so this shows source code so it catch the exception raising and modify error bug trace message with three hearts and the result will be here it can be increased
frustration but the example, easy example and also you can get local variable names so we have binding local variable methods to return the list of local variable names
and also we have binding local variable get method so we can show the the local variable names and corresponding values by the way maybe if you write
a keyword parameter if you can so usually you cannot use if local variable because if is a keyword of Ruby but using binding local variable get method you can get
the value of local variable and also we provide debug inspector gem debug inspector gem is something like core binding but it is supported officially
you can get all binding for stack frames each stack frame and you can get the local variables for each method frames so and also you
can combine these techniques these primitives to make your own suitable to to ring so it means that pretty bug trace gem is written by these techniques maybe so if you don't know about these techniques
then pretty bug trace is you can see you can imagine that it is magical but it's not magical it's not magic you can make it C2B MRI MRI provides such a
low layer primitive so please try these tricks so I want to so I have no time so I want to show only a few things you can make a C extension library using the the low level C APIs
so using C APIs you can get you can control more and more for for C2B MRI and also you can hack Ruby, Ruby is also open source software
and there is a very nice book and you can modify you can build your own Ruby interpreter to check your programs and also you can combine low level two rings
such as GDB and so on and also you can hack the low level system such as Linux Linux is also open source software so you can hack these systems if you need so
maybe you are a base programmer and I agree that the base programming is fun, it's very fun and also low level programming is also fun sometimes so today I want to talk I want to say that you can introspect
your days application with existing tools and also you can make your own inspection tool for your days application in your own your hands so thank you so much