Mercurial > hg > nginx
comparison src/event/ngx_event_openssl.c @ 1017:ee25c79bea34
optimize the SSL session cache allocations on 64-bit platforms
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 11 Jan 2007 18:59:17 +0000 |
parents | 32ebb6b13ff3 |
children | f88651afad40 |
comparison
equal
deleted
inserted
replaced
1016:d0e8c81d3bb7 | 1017:ee25c79bea34 |
---|---|
1234 /* | 1234 /* |
1235 * The length of the session id is 16 bytes for SSLv2 sessions and | 1235 * The length of the session id is 16 bytes for SSLv2 sessions and |
1236 * between 1 and 32 bytes for SSLv3/TLSv1, typically 32 bytes. | 1236 * between 1 and 32 bytes for SSLv3/TLSv1, typically 32 bytes. |
1237 * It seems that the typical length of the external ASN1 representation | 1237 * It seems that the typical length of the external ASN1 representation |
1238 * of a session is 118 or 119 bytes for SSLv3/TSLv1. | 1238 * of a session is 118 or 119 bytes for SSLv3/TSLv1. |
1239 * Thus we allocate separatly an rbtree node, a session id, and an ASN1 | 1239 * |
1240 * representation and on 32-bit platforms they take accordingly 64, 32, and | 1240 * Thus on 32-bit platforms we allocate separately an rbtree node, |
1241 * 128 bytes. | 1241 * a session id, and an ASN1 representation, they take accordingly |
1242 * 64, 32, and 128 bytes. | |
1243 * | |
1244 * On 64-bit platforms we allocate separately an rbtree node + session_id, | |
1245 * and an ASN1 representation, they take accordingly 128 and 128 bytes. | |
1242 * | 1246 * |
1243 * OpenSSL's i2d_SSL_SESSION() and d2i_SSL_SESSION are slow, | 1247 * OpenSSL's i2d_SSL_SESSION() and d2i_SSL_SESSION are slow, |
1244 * so they are outside the code locked by shared pool mutex | 1248 * so they are outside the code locked by shared pool mutex |
1245 */ | 1249 */ |
1246 | 1250 |
1292 ngx_ssl_expire_sessions(cache, shpool, 0); | 1296 ngx_ssl_expire_sessions(cache, shpool, 0); |
1293 | 1297 |
1294 cached_sess = ngx_slab_alloc_locked(shpool, len); | 1298 cached_sess = ngx_slab_alloc_locked(shpool, len); |
1295 | 1299 |
1296 if (cached_sess == NULL) { | 1300 if (cached_sess == NULL) { |
1297 id = NULL; | 1301 sess_id = NULL; |
1298 goto failed; | 1302 goto failed; |
1299 } | 1303 } |
1300 } | 1304 } |
1305 | |
1306 sess_id = ngx_slab_alloc_locked(shpool, sizeof(ngx_ssl_sess_id_t)); | |
1307 if (sess_id == NULL) { | |
1308 goto failed; | |
1309 } | |
1310 | |
1311 #if (NGX_PTR_SIZE == 8) | |
1312 | |
1313 id = sess_id->sess_id; | |
1314 | |
1315 #else | |
1301 | 1316 |
1302 id = ngx_slab_alloc_locked(shpool, sess->session_id_length); | 1317 id = ngx_slab_alloc_locked(shpool, sess->session_id_length); |
1303 if (id == NULL) { | 1318 if (id == NULL) { |
1304 goto failed; | 1319 goto failed; |
1305 } | 1320 } |
1306 | 1321 |
1307 sess_id = ngx_slab_alloc_locked(shpool, sizeof(ngx_ssl_sess_id_t)); | 1322 #endif |
1308 if (sess_id == NULL) { | |
1309 goto failed; | |
1310 } | |
1311 | 1323 |
1312 ngx_memcpy(cached_sess, buf, len); | 1324 ngx_memcpy(cached_sess, buf, len); |
1313 | 1325 |
1314 ngx_memcpy(id, sess->session_id, sess->session_id_length); | 1326 ngx_memcpy(id, sess->session_id, sess->session_id_length); |
1315 | 1327 |
1344 | 1356 |
1345 if (cached_sess) { | 1357 if (cached_sess) { |
1346 ngx_slab_free_locked(shpool, cached_sess); | 1358 ngx_slab_free_locked(shpool, cached_sess); |
1347 } | 1359 } |
1348 | 1360 |
1349 if (id) { | 1361 if (sess_id) { |
1350 ngx_slab_free_locked(shpool, id); | 1362 ngx_slab_free_locked(shpool, sess_id); |
1351 } | 1363 } |
1352 | 1364 |
1353 ngx_shmtx_unlock(&shpool->mutex); | 1365 ngx_shmtx_unlock(&shpool->mutex); |
1354 | 1366 |
1355 ngx_log_error(NGX_LOG_ALERT, c->log, 0, | 1367 ngx_log_error(NGX_LOG_ALERT, c->log, 0, |
1441 sess_id->prev->next = sess_id->next; | 1453 sess_id->prev->next = sess_id->next; |
1442 | 1454 |
1443 ngx_rbtree_delete(cache->session_rbtree, node); | 1455 ngx_rbtree_delete(cache->session_rbtree, node); |
1444 | 1456 |
1445 ngx_slab_free_locked(shpool, sess_id->session); | 1457 ngx_slab_free_locked(shpool, sess_id->session); |
1458 #if (NGX_PTR_SIZE == 4) | |
1446 ngx_slab_free_locked(shpool, sess_id->id); | 1459 ngx_slab_free_locked(shpool, sess_id->id); |
1460 #endif | |
1447 ngx_slab_free_locked(shpool, sess_id); | 1461 ngx_slab_free_locked(shpool, sess_id); |
1448 | 1462 |
1449 sess = NULL; | 1463 sess = NULL; |
1450 | 1464 |
1451 goto done; | 1465 goto done; |
1521 sess_id->prev->next = sess_id->next; | 1535 sess_id->prev->next = sess_id->next; |
1522 | 1536 |
1523 ngx_rbtree_delete(cache->session_rbtree, node); | 1537 ngx_rbtree_delete(cache->session_rbtree, node); |
1524 | 1538 |
1525 ngx_slab_free_locked(shpool, sess_id->session); | 1539 ngx_slab_free_locked(shpool, sess_id->session); |
1540 #if (NGX_PTR_SIZE == 4) | |
1526 ngx_slab_free_locked(shpool, sess_id->id); | 1541 ngx_slab_free_locked(shpool, sess_id->id); |
1542 #endif | |
1527 ngx_slab_free_locked(shpool, sess_id); | 1543 ngx_slab_free_locked(shpool, sess_id); |
1528 | 1544 |
1529 goto done; | 1545 goto done; |
1530 } | 1546 } |
1531 } | 1547 } |
1571 | 1587 |
1572 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, ngx_cycle->log, 0, | 1588 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, ngx_cycle->log, 0, |
1573 "expire session: %08Xi", sess_id->node.key); | 1589 "expire session: %08Xi", sess_id->node.key); |
1574 | 1590 |
1575 ngx_slab_free_locked(shpool, sess_id->session); | 1591 ngx_slab_free_locked(shpool, sess_id->session); |
1592 #if (NGX_PTR_SIZE == 4) | |
1576 ngx_slab_free_locked(shpool, sess_id->id); | 1593 ngx_slab_free_locked(shpool, sess_id->id); |
1594 #endif | |
1577 ngx_slab_free_locked(shpool, sess_id); | 1595 ngx_slab_free_locked(shpool, sess_id); |
1578 } | 1596 } |
1579 } | 1597 } |
1580 | 1598 |
1581 | 1599 |