3. Spaghetti à la tomate de Giuseppina
Plat principal - Facile - Bon marché
Pour 4 personnes
Préparation et cuisson: 20 minutes
Ingrédients:
- 500g de spaghetti
- 6 tomates bien mûres
- 1 oignon
- 1 carotte
- 2 gousses d'ail
- 1 branche de céleri
- huile d'olive
- sauge, romarin, basilic frais
- sel et poivre
- amour
4. Spaghetti à la tomate de Giuseppina
Plat principal - Facile - Bon marché
1. Faire bouillir une grande quantité d'eau (non salée) dans une casserole
2. Pendant ce temps, pelez les tomates et coupez-les grossièrement
3. Epluchez et émincez l'oignon, la carotte, l'ail et le céleri
4. Lorsque l'eau bout, salez-la, puis déposez les spaghettis en couronne
5. Faire chauffer l'huile d'olive dans une sauteuse. Mettez-y à brunir la deuxième gousse d'ail préalablement épluchée.
6. Retirez la gousse d'ail, puis versez le mirepoix (mélange de légumes) et faites revenir à feu vif
7. Ajoutez les tomates, les herbes, salez et poivrez copieusement. Faites chauffer à feu moyen pendant 5 minutes
8. Goûtez régulièrement les spaghettis. Lorsqu'ils sont cuits al dente, égouttez-les puis déposez-les dans un plat chaud.
9. Versez la sauce tomate immédiatement sur les pâtes fumantes. Ajoutez le basilic grossièrement découpé.
10.Servez avec du parmesan rapé et un bon Chianti Classico, et régalez-vous
6. //
time
is
0
$pastaPan
=
new
Pan();
$water
=
new
Water();
$pastaPan-‐>fill($water);
$pastaPan-‐>warm($duration
=
10);
//
now
time
is
10
$pastaPan-‐>fill(new
Spaghetti());
$pastaPan-‐>warm($duration
=
8);
//
now
time
is
18
$pastaPan-‐>remove($water);
!
$saucePan
=
new
Pan();
$saucePan-‐>fill(new
OliveOil());
$saucePan-‐>warm($duration
=
2);
//
now
time
is
20
$saucePan-‐>fill(MirepoixFactory::create($withGarlic
=
true));
$saucePan-‐>warm($duration
=
5);
//
now
time
is
25
$saucePan-‐>fill(TomatoFactory::create());
$saucepan-‐>warm($duration
=
4);
//
now
time
is
29
!
$plate
=
new
Plate();
$plate-‐>addContentsOf($pastaPan);
$plate-‐>addContentsOf($saucePan);
$plate-‐>serve('Régalez-‐vous');
7. LES 3 GRANDS TABOUS
DU DEVELOPPEUR
UTILISER eval()
8. LES 3 GRANDS TABOUS
DU DEVELOPPEUR
INJECTER UN CONTENEUR
D’INJECTION DE DÉPENDANCE
9. LES 3 GRANDS TABOUS
DU DEVELOPPEUR
SERVIR DES
PÂTES FROIDES
14. class
AsynchronousPan
extends
Pan
{
protected
$eventLoop;
public
function
__construct(EventLoop
$eventLoop)
{
$this-‐>eventLoop
=
$eventLoop;
}
public
function
warm($duration,
$callback)
{
$this-‐>eventLoop-‐>executeLater($duration,
$callback);
}
}
22. pastaPan:
Allumage
tic-‐tac
:
1
...
tic-‐tac
:
7
saucePan:
L'huile
chauffe
tic-‐tac
:
8
tic-‐tac
:
9
saucePan:
L'huile
est
chaude
saucePan:
Lancement
de
la
cuisson
du
mirepoix
tic-‐tac
:
10
pastaPan:
L'eau
bout
pastaPan:
Lancement
de
la
cuisson
des
spaghettis
tic-‐tac
:
11
....
tic-‐tac
:
14
saucePan:
Le
mirepoix
est
prêt
pour
la
tomate
saucePan:
Lancement
de
la
cuisson
de
la
tomate
tic-‐tac
:
15
...
tic-‐tac
:
18
pastaPan:
Les
spaghettis
sont
prêts
saucePan:
La
sauce
est
prête
Régalez-‐vous
49. L1
cache
reference
.........................
0.5
ns
L2
cache
reference
...........................
7
ns
Main
memory
reference
......................
100
ns
Compress
1K
bytes
with
Zippy
.............
3,000
ns
=
3
µs
Send
2K
bytes
over
1
Gbps
network
.......
20,000
ns
=
20
µs
SSD
random
read
........................
150,000
ns
=
150
µs
Read
1
MB
sequentially
from
memory
.....
250,000
ns
=
250
µs
Round
trip
within
same
datacenter
......
500,000
ns
=
0.5
ms
Read
1
MB
sequentially
from
SSD*
.....
1,000,000
ns
=
1
ms
Disk
seek
...........................
10,000,000
ns
=
10
ms
Read
1
MB
sequentially
from
disk
....
20,000,000
ns
=
20
ms
Send
packet
CA-‐>Netherlands-‐>CA
....
150,000,000
ns
=
150
ms
Source: http://www.cs.cornell.edu/projects/ladis2009/talks/dean-keynote-ladis2009.pdf
50. I/O = ATTENTE
ETABLISSEMENT CONNEXION SÉCURISÉE
RÉCEPTION REQUÊTE HTTP
REQUÊTE BASE DE DONNÉES
LECTURE VALEUR DANS MEMCACHE
LECTURE DE FICHIER SUR DISQUE
APPEL À UNE API REST
ENVOI MESSAGE À UN AMQP
ENVOI RÉPONSE HTTP
51. 90%
DU TEMPS DE RÉPONSE
D’UNE REQUÊTE HTTP
EST PASSÉ À ATTENDRE UNE I/O
52. GET
/favicon.ico
Process serveur
Routing
Lancement de l’ordre de
chargement du fichier
Déplacement de la tête de lecture
Transfert des données du disque en mémoire
Construction de la réponse HTTP
Traitement
Attente
Envoi de la réponse HTTP
Fin de la requête
68. var
fs
=
require('fs');
fs.unlink('/tmp/hello',
function
(err)
{
if
(err)
throw
err;
console.log('successfully
deleted
/tmp/hello');
});
//
more
code
console.log('deletion
script');
69. plate
=
new
Plate();
pastaPan
=
new
AsynchronousPan(eventLoop);
water
=
new
Water();
pastaPan.fill(water);
console.log('pastaPan:
Starting
to
boil
water');
pastaPan.warm(duration
=
10,
function()
{
console.log('pastaPan:
Water
is
boiling');
pastaPan.fill(new
Spaghetti());
console.log('pastaPan:
Starting
to
boil
spaghetti');
pastaPan.warm(duration
=
8,
function()
{
console.log('pastaPan:
Spaghetti
is
ready');
pastaPan.remove(water);
plate.addContentsOf(pastaPan);
});
});
70. $plate
=
new
Plate();
$pastaPan
=
new
AsynchronousPan($eventLoop);
$water
=
new
Water();
$pastaPan-‐>fill($water);
echo
"pastaPan:
Starting
to
boil
watern";
$pastaPan-‐>warm($duration
=
10,
function()
use
($pastaPan,
$plate,
$water)
{
echo
"pastaPan:
Water
is
boilingn";
$pastaPan-‐>fill(new
Spaghetti());
echo
"pastaPan:
Starting
to
boil
spaghettin";
$pastaPan-‐>warm($duration
=
8,
function()
use
($pastaPan,
$plate,
$water)
{
echo
"pastaPan:
Spaghetti
is
readyn";
$pastaPan-‐>remove($water);
$plate-‐>addContentsOf($pastaPan);
});
});
71. I/O ASYNCHRONES
UN SEUL CHEF
DES CALLBACKS
PLUS DE CONCURRENCE
MOINS DE CONSOL MÉMOIRE
PAS POSSIBLE EN PHP, NATIF EN NODE.JS
PAS DE RETURN, PAS DE TRY/CATCH